ID: 15673 Updated by: [EMAIL PROTECTED] -Summary: Quotes crash MySQL queries: $array['val'] = Parse Error, but $array[val] works Reported By: [EMAIL PROTECTED] Status: Analyzed Bug Type: Arrays related Operating System: Linux 2.4.5 PHP Version: 4.1.1 New Comment:
And the Parse Error, do you get it with the cvs ver too? Previous Comments: ------------------------------------------------------------------------ [2002-02-22 08:29:58] [EMAIL PROTECTED] Ah, I see. No, there's no warning either. ------------------------------------------------------------------------ [2002-02-22 08:25:33] [EMAIL PROTECTED] Yes, I know your code works, thats not the problem. Now change your own code: echo $foo[key]; ==to==> echo "Key value is $foo[key]"; // No warnings!!!!! And then TRY: echo "$foo['key']"; // PARSE ERROR!!! Does it happens with the cvs version? ------------------------------------------------------------------------ [2002-02-22 08:12:54] [EMAIL PROTECTED] Work's right with CVS: $ php <? error_reporting(E_ALL); $foo['key'] = 'value'; echo $foo[key]; ?> X-Powered-By: PHP/4.2.0-dev Content-type: text/html <br /> <b>Warning</b>: Use of undefined constant key - assumed 'key' in <b>-</b> on line <b>4</b><br /> -(4) : Warning - Use of undefined constant key - assumed 'key' ------------------------------------------------------------------------ [2002-02-22 07:52:32] [EMAIL PROTECTED] I did this tests using error_reporting(E_ALL); Thats my point, the correct array syntax according the doc: http://www.php.net/manual/en/language.types.array.php is to call $array['value'] even thought $array[value] will work, but in the later case it should send a NOTICE warning. well, try this in you system: error_reporting(E_ALL); $arr = array( 'foo' => 'bar', 'etc' => 'other'); //This will make a Parse Error in PHP 4.1.1: //echo "Foo value is $arr['foo']"; //This works: echo "Foo value is ".$arr['foo']; echo "Foo value is {$arr['foo']}"; //This will work but WON'T send a warning as the doc says: echo "Foo value is $arr[foo]"; // This will get a parse error echo "Foo value is $arr['foo']"; ------------------------------------------------------------------------ [2002-02-22 07:40:57] [EMAIL PROTECTED] Yes, I get you get a NOTICE warning when you use $array[key] (because key will be an undefined constant and therefore evaluate to a string). Try with error_reporting(E_ALL); before using this syntax. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/15673 -- Edit this bug report at http://bugs.php.net/?id=15673&edit=1