ID: 41542 Updated by: [EMAIL PROTECTED] Reported By: linfo2003 at libero dot it -Status: Open +Status: Bogus Bug Type: Variables related Operating System: WindowsXP PHP Version: 5.2.2 New Comment:
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Passing a variable by reference is expected to create it. Previous Comments: ------------------------------------------------------------------------ [2007-05-30 15:11:41] linfo2003 at libero dot it Description: ------------ The '@' operator to not only suppresses non-fatal errors, but it seems that it changes the behaviour of the code. I don't know if it's a bug or a normal behaviour. The fact is that if you pass by reference an undefined index of an array to a function, that index will be defined and set to NULL. While if you use the '@' operator, this won't happen. See the code. Reproduce code: --------------- error_reporting(E_ALL); print '<pre>'; function byVal( $v) {} function byRef(&$v) {} echo "byVal(first['undefined'])\n"; byVal ($first['undefined']); // gives a notice echo "var_dump(first)\n"; var_dump($first); // gives a notice print '<hr />'; echo "byRef(second['undefined'])\n"; byRef ($second['undefined']); // does NOT give a notice echo "var_dump(second)\n"; var_dump($second); // does NOT give a notice print '<hr />'; echo "byRef(@third['undefined'])\n"; byRef (@$third['undefined']); // does NOT give a notice echo "var_dump(third)\n"; var_dump($third); // gives a notice Expected result: ---------------- The $second or the $third case should be wrong, IMHO. AKAIK, the '@' operator should only suppress the notice, while it's changing the behaviour of the code, by not defining the $third array and not defining the 'undefined' index into the $third array. I don't know if the $second case is an expected behaviour, maybe it should NOT add the 'undefined' index into the (undefined) $third array. However, is a fact that the '@' operator makes something unexpected: it does NOT only suppress the notice. Actual result: -------------- byVal(first['undefined']) Notice: Undefined variable: first in ... on line 12 var_dump(first) Notice: Undefined variable: first in ... on line 14 NULL ----------------------------------------------------- byRef(second['undefined']) var_dump(second) array(1) { ["undefined"]=> NULL } ----------------------------------------------------- byRef(@third['undefined']) var_dump(third) Notice: Undefined variable: third in ... on line 28 NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41542&edit=1