Bug #55278 [Com]: @ Error control operator prevents creation of variable

From: Date: Thu, 28 Jul 2011 02:32:55 +0000
Subject: Bug #55278 [Com]: @ Error control operator prevents creation of variable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-162233@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55278&edit=1

 ID:                 55278
 Comment by:         lucas at threeamdesign dot com
 Reported by:        lucas at threeamdesign dot com
 Summary:            @ Error control 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:

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"


Previous Comments:
------------------------------------------------------------------------
[2011-07-26 05:05:11] laruence@php.net

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


Thread (4 messages)

« previous php.bugs (#162233) next »