|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-08-08 15:11 UTC] 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'
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 20:00:01 2025 UTC |
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)More info: my system is a virtualized debian 64 bit machine running on a Mac,,, the production server where we discovered the problem is an dedicated debian 64 box (php versions listed in original comment). Sorry for not posting the exact output before! Here's a modified script that shows the correct value of $b before the notice: class A{ function do_stuff(&$b) { var_dump('Before in function:', $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('After in function:', $b); } } class B{} $a = new A(); $b = new B(); $a->do_stuff($b); var_dump('After function:', $b); --------------- output of above ------------------ string 'Before in function:' (length=19) object(B)[10] ( ! ) Notice: Undefined variable: undefined in /vagrant/src/temp.tmp.php on line 7 Call Stack # Time Memory Function Location 1 0.1017 4382640 {main}( ) ../temp.tmp.php:0 2 0.1018 4385776 A->do_stuff( ) ../temp.tmp.php:17 string 'After in function:' (length=18) string 'B' (length=1) string 'After function:' (length=15) string 'B' (length=1)