From: linfo2003 at libero dot it
Operating system: WindowsXP
PHP version: 5.2.2
PHP Bug Type: Variables related
Bug description: The '@' operator changes the behaviour of the code
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 bug report at http://bugs.php.net/?id=41542&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=41542&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=41542&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=41542&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41542&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=41542&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41542&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41542&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41542&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41542&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41542&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=41542&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=41542&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41542&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41542&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41542&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41542&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41542&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41542&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41542&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41542&r=mysqlcfg