Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP und Objekte, Objektvariablen, Membervariablen

Empfohlene Antworten

Veröffentlicht

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

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.

er meinte anstatt

$this->$actualMonth

so

$this->actualMonth

der 2. dollar ist zu viel

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.