Bug #67807 [Com]: Object passed by reference becomes a string
| From: | atlantisnova at gmail dot com | Date: | Fri, 08 Aug 2014 17:22:56 +0000 |
| Subject: | Bug #67807 [Com]: Object passed by reference becomes a string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187029@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67807&edit=1
ID: 67807
Comment by: atlantisnova at gmail dot com
Reported by: atlantisnova at gmail dot com
Summary: Object passed by reference becomes a string
Status: Feedback
Type: Bug
Package: Class/Object related
Operating System: Debian Linux
PHP Version: 5.4.4
Block user comment: N
Private report: N
New Comment:
Yes it's exact and sure here's the output:
( ! ) Notice: Undefined variable: undefined in /vagrant/src/temp.tmp.php on line 6
Call Stack
# Time Memory Function Location
1 0.0631 4382248 {main}( ) ../temp.tmp.php:0
2 0.0631 4385384 A->do_stuff( ) ../temp.tmp.php:16
string 'In function:' (length=12)
string 'B' (length=1)
string 'After function:' (length=15)
string 'B' (length=1)
Previous Comments:
------------------------------------------------------------------------
[2014-08-08 17:18:15] requinix@php.net
http://3v4l.org/VqsdQ Works for me.
That's the exact repro script you used? And rather than some description of the actual result,
how about posting the actual, actual result?
------------------------------------------------------------------------
[2014-08-08 15:11:22] atlantisnova at gmail dot com
Description:
------------
My version is PHP 5.4.4-14+deb7u7... Also affects PHP 5.4.4-14+deb7u11 - the production server we
discovered it on.
It seems that any sort of notice in a function into which an object has been passed by reference
replaces the reference with a string containing its class name.
Code executed after the pass-by-reference also receives the string rather than the original object.
Thanks!
Test script:
---------------
class A{
function do_stuff(&$b) {
$defined = 0;
#trigger_error("If I fixed the undefined variable but enabled this line instead, it will also
turn b from an object into a string! So user-triggered notices bork it as well.");
$x = $undefined || $defined ? 14 : 0;
var_dump('In function:', $b);
}
}
class B{}
$a = new A();
$b = new B();
$a->do_stuff($b);
var_dump('After function:', $b);
Expected result:
----------------
$b should be an object of class B
Actual result:
--------------
$b is the string 'B'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67807&edit=1