Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 09.03.07 17:20 
Warum wird die if-Abfrage nie true? Die Ausgabe ergibt: 20078. Also $year = 2007 und $month = 8.
"here" wird also nie ausgegeben. :gruebel:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  function Calender($month,$year) {
    echo $year;
    echo $month;
    if (is_numeric($year) && is_numeric($month)) {
      echo "here";
      $this->SetYear($year);
      $this->SetMonth($month);
    }
    else {
      $this->year = date('Y');
      $this->month = date('m');
    }
  }

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Bex
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Win XP, Linux
C# (VS 2008), Java (Eclipse)
BeitragVerfasst: Fr 09.03.07 17:33 
Wo werden denn $year und $month erzeugt, wie wird die Funktion aufgerufen? Sind das tatsächlich numerics?
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 09.03.07 17:59 
Funktion wird so aufgerufen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
if ($mode == 'calender') {
  $month = $_GET['month'];
  $year = $_GET['year'];
  $calender = new Calender($month,$year);
  echo $calender->CreateHeader();
}

Es sind numerics: 2007 und 8 sind doch wohl numerics?!? Oder muss ich dir irgendwie umwandeln. Ich gehe atm davon aus, dass der Interpreter das automatisch als solchen behandelt.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
alcaeus
half ontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 226



BeitragVerfasst: Fr 09.03.07 18:08 
Mein Tipp: Boxe die variablen auf den Typen den du haben willst:
ausblenden Quelltext
1:
2:
$year = (int) $year;
$month = (int) $month;


Sehr zu empfehlen fuer GPC-Variablen :)

Und ja, eigentlich sollten das numerics sein, von welcher PHP-Version sprechen wir denn?

Greetz
alcaeus
Bex
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Win XP, Linux
C# (VS 2008), Java (Eclipse)
BeitragVerfasst: Fr 09.03.07 18:11 
Ich würde tippen, die per $_GET geholten Parameter sind Strings ...
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 09.03.07 18:11 
user profile iconalcaeus hat folgendes geschrieben:
Mein Tipp: Boxe die variablen auf den Typen den du haben willst:
ausblenden Quelltext
1:
2:
$year = (int) $year;
$month = (int) $month;

Werde ich probieren. Diese Methode war mir durchaus bekannt, nur dachte ich, is_numeric kommt damit klar.
user profile iconalcaeus hat folgendes geschrieben:
Sehr zu empfehlen fuer GPC-Variablen :)

Was sind GPC-Variablen?
user profile iconalcaeus hat folgendes geschrieben:

Und ja, eigentlich sollten das numerics sein, von welcher PHP-Version sprechen wir denn?

Version 5.0.4. => Läuft bei mir über xampp.
user profile iconbex hat folgendes geschrieben:

Ich würde tippen, die per $_GET geholten Parameter sind Strings ...

Ja sind sie ja auch, aber sie sind ja gewissermaßen auch Zahlen, deswegen ging ich davon aus, dass is_numeric zutrifft.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Bex
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Win XP, Linux
C# (VS 2008), Java (Eclipse)
BeitragVerfasst: Fr 09.03.07 18:17 
Muss an der Stelle passen, bin stark typisierte Sprachen gewohnt (Java, C#) ... ;-)
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 09.03.07 18:18 
user profile iconBex hat folgendes geschrieben:
Muss an der Stelle passen, bin stark typisierte Sprachen gewohnt (Java, C#) ... ;-)

Kein Problem. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 09.03.07 18:31 
Jep, würde es trotzdem mit int umwandeln. Ich kenn das Problem von ActionScript (seit neuestem mein Gebiet :lol:). Selbst bei Zahlen, kann es vorkommen, dass der Interpreter mir an den Kopf wirft, dass er Zahlen braucht. Bei ActionScript wäre dann die Umwandlung einfach Number(x);.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
alcaeus
half ontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 226



BeitragVerfasst: Fr 09.03.07 18:36 
Denke dir diesen Code:
ausblenden Quelltext
1:
2:
3:
$year = '2007';
echo "is_numeric: ". ((is_numeric($year)) ? 'True' : 'False') .'';
echo "is_int: ". ((is_int($year)) ? 'True' : 'False') .'';


Bei mir (PHP 5.1.irgendwas) ergibt das erste True, das zweite False; also so wie es sein sollte. Manchmal kommt es vor, dass sich PHP dabei aber verschluckt.

Weil du gefragt hast: GPC-Variablen sind $_GET, $_POST, $_COOKIE; also alles das von "aussen" kommt und deshalb unsicher ist.

Ich habe mir eine Funktion namens request_gpc gebaut, die mir alles aus den GPC-Variablen raussaugen, so wie ich es will. Die Funktion macht auch eine strenge Typkonvertierung. Bei Interesse kann ich die Funktionen ja veroeffentlichen.

Greetz
alcaeus
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 09.03.07 19:16 
Die Funktion würde mich interessieren. ;)
Aber warum is_numeric nun bei mir false ergibt, ist mir immer noch nicht klar. Oder habe ich was überlesen?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
alcaeus
half ontopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 226



BeitragVerfasst: Fr 09.03.07 19:41 
Das mit is_numeric() ist mir auch nicht klar. Aber wie du dir vielleicht denken kannst, ich hab solche Probleme nicht :mrgreen:

Die Funktion ist eigentlich mehr ne ganze Klasse...natuerlich mit statischen Methoden. Ich hab das Ganze mal online gestellt und beschrieben: www.alcaeus.org/viewtopic.php?t=292

Greetz
alcaeus