Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   [PHP] Globale Variablen (https://www.delphipraxis.net/70705-%5Bphp%5D-globale-variablen.html)

3_of_8 3. Jun 2006 01:31


[PHP] Globale Variablen
 
Morgen.

Noch ein Problem mit PHP.

Ich habe grade folgendes probiert:

Code:
global $blubb;

function foo() {
$blubb["abc"]="wuppdi";
}

function bar() {
echo($blubb["abc"]);
}

foo();
bar();
Was bekomme ich? Natürlich eine leere Ausgabe. Wäre sonst auch zu leicht gewesen. ;)

Was mache ich da falsch? Welche Einstellung verbockt das?

Wenn ich statt $blubb["abc"] schreibe $GLOBALS["blubb"]["abc"] geht es seltsamerweise.

titus 3. Jun 2006 01:44

Re: [PHP] Globale Variablen
 
Es muss heißen:
Code:
function foo() {
  global $blubb;
  $blubb["abc"]="wuppdi";
}

function bar() {
  global $blubb;
  echo($blubb["abc"]);
}

foo();
bar();
Die Variable wird nicht als global "markiert"/gesetzt, sondern in der Funktion als global angesehen (so in etwa).

Zitat:

Wenn ich statt $blubb["abc"] schreibe $GLOBALS["blubb"]["abc"] geht es seltsamerweise.
Ist auch klar:
Die Variable wird in dem Fall als global "markiert"/gesetzt.

mfG, titus

3_of_8 3. Jun 2006 09:44

Re: [PHP] Globale Variablen
 
Aaah... Klingt fast logisch. :lol:

Danke.


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz