PHP4 array definition irregularity in class variables

From: Date: Sun, 04 Jun 2000 15:44:07 +0000
Subject: PHP4 array definition irregularity in class variables
Groups: php.general 
Request: Send a blank email to php-general+get-979@lists.php.net to get a copy of this message
Found some odd behavior of PHP4 that didn't previously exist in PHP3. Curious if it's a bug, or if it's intended behavior. Also curious about ideas on how to work around it... I ran across this problem when converting an app that uses PHPLib's Menu class from PHP3 to PHP4. I'll provide a simple example here, instead of confusing the issue with the wacky stuff that goes on within the Menu class. When defining an array, it appears that PHP allows you to provide an expression as the key to an associative array... like this: <? $blah = array(("foo" . "bar") => "Testing"); print($blah["foobar"]); ?> In both PHP3 and PHP4, the above will result in the word 'Testing' being printed out. However, the same technique applied inside of a class continues to work in PHP3, but fails in PHP4. The following code: <? class Poodle { var $blah = array(("foo" . "bar") => "Testing"); function Print_Blah() { print($this->blah["foobar"]); } } $myDog = new Poodle; $myDog->Print_Blah(); ?> Works fine in PHP3, but yields a "Parse error: parse error, expecting ")" in /www/test.php on line 4" under PHP4.0.0 Any thoughts or insight would be appreciated! --Josh

« previous php.general (#979) next »