ID: 41542 Updated by: [EMAIL PROTECTED] Reported By: linfo2003 at libero dot it Status: Bogus Bug Type: Variables related Operating System: WindowsXP PHP Version: 5.2.2 New Comment:
>But AFAIK, only *variables* can be passed by reference. Exactly. Add E_STRICT to the error level and you'll see a message about it. Previous Comments: ------------------------------------------------------------------------ [2007-05-30 16:06:22] linfo2003 at libero dot it But AFAIK, only *variables* can be passed by reference. However, if you say it's a normal behaviour, I'll trust you. Thank you for your courtesy. ------------------------------------------------------------------------ [2007-05-30 16:00:26] [EMAIL PROTECTED] @$var is not a variable, it's an expression. So you end up passing result of this expression to the function, not the variable itself. ------------------------------------------------------------------------ [2007-05-30 15:43:01] linfo2003 at libero dot it Then it's the $third case that is wrong. byRef(@$third['undefined']) does NOT creates that index. Should the '@' operator only suppress the notice? Then that index should be added to the $third array. It isn't added. Is this a normal behaviour? Thanks. ------------------------------------------------------------------------ [2007-05-30 15:38:36] [EMAIL PROTECTED] 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. ------------------------------------------------------------------------ [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
