note 72741 deleted from function.define by tularis

From: Date: Sun, 03 Jun 2007 09:36:57 +0000
Subject: note 72741 deleted from function.define by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127140@lists.php.net to get a copy of this message
Note Submitter: alf ---- Couldn't see this beeing brought up, so I write it here so all can be clear: <?php define('test', 8); $foo[8] = "debug 1"; $foo['test'] = "debug 2"; print $foo[test]; // "debug 1" print $foo['test']; // "debug 2" ?> What happens when we use a string variable as key? <?php $str = "test"; print $foo[$str]; ?> One (wrong) way of reasoning: => $str outputs just test (without quotes) => $foo[$str] should then translate to $foo[test] => $foo[test] whould translate to $foo[8] (because test is a defined constant) => output should then be "debug 1" This is wrong! ..but I'm sure I'm not the only one who thought about this.. ;) Both $foo[$str] and $foo["$str"] outputs "debug 2"

« previous php.notes (#127140) next »