[PHP-BUG] Bug #55278 [NEW]: @ Error control operator prevents creation of variable
From: Operating system: Windows 7 PHP version: 5.3.6 Package: Scripting Engine problem Bug Type: Bug Bug description:@ Error control operator prevents creation of variable 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: --- https://bugs.php.net/bug.php?id=55278&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55278&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55278&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55278&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55278&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55278&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55278&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55278&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55278&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55278&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55278&r=support Expected behavior: https://bugs.php.net/fix.php?id=55278&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55278&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55278&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55278&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55278&r=php4 Daylight Savings:https://bugs.php.net/fix.php?id=55278&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55278&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55278&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55278&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55278&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55278&r=mysqlcfg
Bug #55278 [Com]: @ Error control operator prevents creation of variable
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] larue...@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: --- https://bugs.php.net/bug.php?id=55278&edit=1
Bug #55278 [Dup]: @ (Error control/suppression) operator prevents creation of variable
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] larue...@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: --- https://bugs.php.net/bug.php?id=55278&edit=1
Bug #52937 [Com]: call_user_func warning is inappropriate
Edit report at https://bugs.php.net/bug.php?id=52937&edit=1 ID: 52937 Comment by: lucas at threeamdesign dot com Reported by:mryaggi at hotmail dot com Summary:call_user_func warning is inappropriate Status: Open Type: Bug Package:Scripting Engine problem Operating System: Seven PHP Version:5.3.3 Block user comment: N Private report: N New Comment: to work around this problem put the reference in the argument array. e.g.: function foo(&$bar) { $bar = 5; } $a = 1; $b = 2; call_user_func('foo', $a); call_user_func_array('foo', array(&$b)); var_dump($a, $b); gives int(1) int(5) Previous Comments: [2010-10-11 11:00:54] mryaggi at hotmail dot com Ok, I'm going to keep it simple. You say "[I] have to use call_user_func_array instead". Please show me how. Note : I'm just trying to avoid the warning properly. This would be quite a solution : call_user_func('ExprectRef', & $p); call_user_func_array('ExprectRef',array( & $p)); But it's a pity you have to write & TWICE. One in the signature, one in the call_user_func call. ...it looks so much like the depreciated call-time pass-by-reference. Don't you think? [2010-10-03 00:02:58] cataphr...@php.net You *should* know whether the function takes references; it's part of its signature. If it does take references you cannot use call_user_func, and have to use call_user_func_array instead. [2010-09-29 19:31:10] mryaggi at hotmail dot com Thank you for your quick reply. You say : "Use call_user_func_array()." But you can run the test script with call_user_func_array() instad, and still you will get those warnings. My point is : when you call call_user_func you have no idea whether the function called expects references or not (values). The only solution I see is to always give references to call_user_func*() For ex: - function MY_call_user_func_array($Func,$Args) { foreach(array_keys($Args) as $i) { $Args[$i] =& $Args[$i]; }//make it a ref call_user_func_array($Func,$Args); } function test(&$z){ echo "ok : " . $z . "\n";} $a = 1; MY_call_user_func_array('test',array($a)); - And here we are! IT WORKS! but it I feel like I just learnt how to poo in PHP... [2010-09-28 03:13:28] cataphr...@php.net Yes, this may be confusing. The problem is that the level of indirection added means when the function test() is actually called by the implementation of call_user_func() via zend_call_function, information about the arguments is lost. Use call_user_func_array(). Tests 1 and 3 are basically the same. The manual for call_user_func has a note: «Note that the parameters for call_user_func() are not passed by reference.» Since call_user_func doesn't receive its parameters by reference, by the time they reach it, it has no way of knowing if the parameters were sent by reference or not. Test 2 is a different matter. But you are actually passing a reference to test() because zend_call_function() is nice and when you pass a non-reference to a function that expects a reference and the non-reference has refcount 1, it converts it into a reference. See http://lxr.php.net/opengrok/xref/PHP_TRUNK/Zend/zend_execute_API.c#860 Again, this makes sense if you're writing an extension and using zend_call_function() and passing it a variable you've created. I don't see how this can be fixed, except by adding something like fci->no_separation that doesn't create a reference even if the refcount is 1. Not sure if it's worth the trouble. [2010-09-27 19:31:16] mryaggi at hotmail dot com Description: call_user_func now issue a warning in PHP5.3 when giving a value instead of a reference. However, this warning shows up in inappropriate cases. Test script: --- Expected result: ok : 1 Warning: Parameter 1 to test() expected to be a reference, value given in ... ok : 3 Actual result: -- Warning: Parameter 1 to test() expected to be a reference, value given in ... ok : 2 Warning: Parameter 1 to test() expected to be a reference, value given in ... -- Edit this bug report at https://bugs.php.net/bug.php?id=52937&edit=1