php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55278 @ (Error control/suppression) operator prevents creation of variable
Submitted: 2011-07-25 03:22 UTC Modified: 2011-07-28 02:34 UTC
From: lucas at threeamdesign dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5.3.6 OS: Windows 7
Private report: No CVE-ID: None
 [2011-07-25 03:22 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-26 05:05 UTC] laruence@php.net
-Status: Open +Status: Duplicate
 [2011-07-26 05:05 UTC] laruence@php.net
this is a duplicate,  see #47623
 [2011-07-28 02:32 UTC] 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-28 02:34 UTC] lucas at threeamdesign dot com
-Summary: @ Error control operator prevents creation of variable +Summary: @ (Error control/suppression) operator prevents creation of variable
 [2011-07-28 02:34 UTC] lucas at threeamdesign dot com
Made this bug easier to search for.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC