|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-05-30 15:38 UTC] tony2001@php.net
[2007-05-30 15:43 UTC] linfo2003 at libero dot it
[2007-05-30 16:00 UTC] tony2001@php.net
[2007-05-30 16:06 UTC] linfo2003 at libero dot it
[2007-05-30 16:10 UTC] tony2001@php.net
[2007-05-30 16:33 UTC] linfo2003 at libero dot it
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
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