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: Variable wird als Referenz übergeben?

Empfohlene Antworten

Veröffentlicht

Hallo, schon wieder ein Problem.

Also ich mache folgendes in einer Methode:


function ausgabe()
{
$htmlcode = $this->ausgabe_string;
$this->ausgabe_string = "";
return $htmlcode;
}
[/PHP]

In diesem Fall wird komischerweise nichts returnd. Daraus schließe ich, dass $this->ausgabe_string = ""; auch die Variable $htmlcode löscht. Aber das davor ist doch eine ganz normale Wertzuweisung und nichts mit Referenzen, oder hab ich was übersehen? Wenn ich die Zeile $this->ausgabe_string = ""; auskommentiere wird der richtige String returnd, aber ich möchte halt auch die Klassenvariable auf "" setzen. Wie kann ich das machen?

Hi

Hm wenn in ausgabe_string schon was drinnen steht bevor diese Methode bei dir aufgerufen wird, dann sollte das so funktionieren...

Gruß,

Markus

genau, $htmlcode kann nur leer sein, wenn $this->ausgabe_string vorher schon leer war. Du solltest zum debuggen einfach mal $this->ausgabe_string ausgenen:

function ausgabe()

    {

        echo $this->ausgabe_string; 


        $htmlcode = $this->ausgabe_string;        

        $this->ausgabe_string = "";

        return $htmlcode;

    } 

ich werd noch wahnsinnig. Irgendwie geht das einfach ncht. Hier sind einfach mal meine Versuche:

(Anmerkung: Der return-Wert gebe ich beim funktionsaufruf so aus: echo $xhtml->ausgabe();

-----------------------------

Gibt den Text 2 mal aus! => Also $htmlcode wird nicht gelöscht:

function ausgabe()

{
$htmlcode = $this->ausgabe_string;
echo $htmlcode;
$this->ausgabe_string = "";
echo $htmlcode;
//return $htmlcode;
}
[/PHP]

Gibt den Text einmal aus:

[PHP]function ausgabe()
{
$htmlcode = $this->ausgabe_string;
$this->ausgabe_string = "";
echo $htmlcode;
//return $htmlcode;
}

Gibt nichts aus, obwohl ich den return-Wert mit echo ausgeben will:

function ausgabe()
{
$htmlcode = $this->ausgabe_string;
$this->ausgabe_string = "";
return $htmlcode;
}[/PHP]

---------------------------------

=> Frage, hat Return irgendwelche Größen/Längebeschränkungen? Ich hab nichts derartiges im Internet gefunden.

Hi,

verwendest du eine PHP5 Version im frühen stadium? Wenn ja, auf die neuste Vers updaten...

Gruß,

Markus

sorry, hab das Problem wo anders gefunden. Ich hatte eine weitere Methode, die die Ausgabe() aufgerufen hatt. Die Ausgabe in der anderen Methode hat nicht funktioniert und deshalb wurde machnmal der Rückgabewert auf "" gesetzt.

Trotzdem danke und ein großes Sorry wegen euren Bemühungen.

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.