Edit report at https://bugs.php.net/bug.php?id=55278&edit=1
ID: 55278
User updated by: lucas at threeamdesign dot com
Reported by: lucas at threeamdesign dot com
-Summary: @ Error control operator prevents creation of
variable
+Summary: @ (Error control/suppression) operator prevents
creation of variable
Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 7
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
Made this bug easier to search for.
Previous Comments:
------------------------------------------------------------------------
[2011-07-28 02:32:55] lucas at threeamdesign dot com
Thanks, glad it wasn't just me. I did search for it but I'm not surprised I
didn't find it - you can't search for "@" so I looked for "error control" and
"error suppression"
------------------------------------------------------------------------
[2011-07-26 05:05:11] [email protected]
this is a duplicate, see #47623
------------------------------------------------------------------------
[2011-07-25 03:22:23] lucas at threeamdesign dot com
Description:
------------
When a function is defined with a parameter that is passed by reference,
calling the function with a variable that has not been previously set will
create that variable (and trigger a warning). After the function is called that
variable exists (won't trigger warnings) and holds null or whatever value the
function assigned to it.
If you try to suppress the warning for the variable that doesn't exist at call
time, it will not be created, and trying to access it after the function
triggers warnings.
It works as expected if you suppress errors on the function call but this is
not desirable because it will also hide other errors.
Test script:
---------------
<?php
function foo(&$bar) {
$bar = 'woo';
}
@foo($x);
foo(@$y);
var_dump($x, $y);
Expected result:
----------------
string(3) "woo"
string(3) "woo"
Actual result:
--------------
Notice: Undefined variable: y in FILE on line LINE
string(3) "woo"
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55278&edit=1