10. Dezember 200520 j Warum kommt hier die unten stehende Ausgabe? class Kalender { var $nextMonth; var $lastMonth; var $actualMonth; function Kalender() { $heute = getDate(); $this->$actualMonth = $heute["mon"]; echo $this->$actualMonth. "<br/>"; if ($this->$actualMonth == 12) { $this->$nextMonth = 1; } else $this->$nextMonth = $this->$actualMonth + 1; echo "actualMonth: " . $this->$actualMonth . ", lastMonth: " . $this->$lastMonth . ", nextMonth: " . $this->$nextMonth . "<br/>"; if ($this->$actualMonth == 1) $this->$lastMonth = 12; else $this->$lastMonth = $this->$actualMonth - 1; echo "actualMonth: " . $this->$actualMonth . ", lastMonth: " . $this->$lastMonth . ", nextMonth: " . $this->$nextMonth; } } $testKalender = new Kalender(); [/PHP] Ausgabe: 12 actualMonth: 1, lastMonth: 1, nextMonth: 1 actualMonth: 12, lastMonth: 12, nextMonth: 12 Ohne die ganzen "$this->" funktioniert es, allerdings kann ich dann nicht mehr auf die Objektvariablen mittels [PHP]echo "LAST:" . $testKalender->$lastMonth; PS: Irgendwie verwirrt mich das, in Java war das alles nicht so kompliziert. Verwende PHP 4.3.2
11. Dezember 200520 j Schau dir mal dieses Beispiel an - dann dürfte klar sein, warums mit $this nicht funktioniert (das $ hinter -> ist zu viel). Was du außerdem vergessen hast, ist der Konstruktur, in dem, wie dir von Java bekanntsein dürfte, alle Variablen initialisiert werden.
11. Dezember 200520 j Autor okay, habe verstanden. allerdings ist der konstruktor doch "function Kalender()" !???????
11. Dezember 200520 j er meinte anstatt $this->$actualMonth so $this->actualMonth der 2. dollar ist zu viel
11. Dezember 200520 j Autor danke für die hilfe. bitte diesen thread löschen, er ist der datenhaltung nicht würdig weil er zu banal ist
Archiv
Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.