Bug #74690 [Ver->Wfx]: PHP throws reference notice when using namespaces.

From: Date: Sat, 12 Aug 2017 00:13:12 +0000
Subject: Bug #74690 [Ver->Wfx]: PHP throws reference notice when using namespaces.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210620@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74690&edit=1 ID: 74690 Updated by: ajf@php.net Reported by: contact at greg dot md Summary: PHP throws reference notice when using namespaces. -Status: Verified +Status: Wont fix Type: Bug Package: Scripting Engine problem Operating System: Mac PHP Version: 7.1.5 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2017-06-02 16:35:53] nikic@php.net No, the notice should occur, because call_user_func_array() does not return by reference. You are right that it does not occur because we're effectively compiling this to a direct call without the indirection in the non-namespaced case, but this doesn't change the fact that a notice should be thrown. As a rule of thumb, if cuf/a behaves differently depending on whether it's in a namespace or not, then the namespaced behavior is always correct. That being said, I don't think we're going to fix this. ------------------------------------------------------------------------ [2017-06-02 15:49:41] requinix@php.net More specific: the notice is only in a namespace and with an unqualified "call_user_func_array". It does not warn outside of a namespace (or in the global namespace) or with the fully-qualified "\call_user_func_array". > The error is about the weird extra ampersand that is in front of the > "&call_user_func_array" . It is complaining that you're trying to reference > the > return value of the function by reference. That ampersand is required to properly use functions that return by-ref: one in the function declaration to return its value by-ref, then another in the assignment to assign by-ref. The latter is really more of a =& operator but with optional whitespace between the two characters. This is all documented: https://secure.php.net/manual/en/language.references.return.php > The bug here is that the notice does not occur in the non-namespaced case. The notice *shouldn't* occur. call_user_func and call_user_func_array get special treatment during compilation - a discrepancy between there and the ZEND_ASSIGN_REF handler is why there's a notice. If it were a regular function call then there wouldn't be any problem. https://3v4l.org/D0Chh ------------------------------------------------------------------------ [2017-06-02 10:07:56] contact at greg dot md It is definitely a bug. If you will remove namespace from the example, it will work as expected and will return the reference of the $foo in $bar, which is expected. With that namespace at the top of the file looks like I can not return by reference using the "&call_user_func_array". Please do the same test with the namespace in the top of the file and without it. ------------------------------------------------------------------------ [2017-06-02 10:02:02] nikic@php.net The bug here is that the notice does not occur in the non-namespaced case. ------------------------------------------------------------------------ [2017-06-02 09:53:34] danack@php.net The error is about the weird extra ampersand that is in front of the "&call_user_func_array" . It is complaining that you're trying to reference the return value of the function by reference. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=74690 -- Edit this bug report at https://bugs.php.net/bug.php?id=74690&edit=1

« previous php.bugs (#210620) next »