#33061 [Asn->WFx]: Pass object by value then modify initialized sub-object: passes by reference

From: Date: Wed, 15 Mar 2006 08:28:32 +0000
Subject: #33061 [Asn->WFx]: Pass object by value then modify initialized sub-object: passes by reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-94359@lists.php.net to get a copy of this message
 ID:               33061
 Updated by:       derick@php.net
 Reported By:      online at natweiss dot com
-Status:           Assigned
+Status:           Wont fix
 Bug Type:         Class/Object related
 Operating System: *
 PHP Version:      4CVS-2005-06-21
 Assigned To:      dmitry
 New Comment:

This patch (by dmitry) fixes it:
http://files.derickrethans.nl/patches/bug33061-2006-03-15.diff.txt

But we can not commit this as this might break backward compatibility,
and we don't want to do that in PHP 4.


Previous Comments:
------------------------------------------------------------------------

[2005-06-21 18:21:34] sniper@php.net

Dmitry: The catch is that you need to call some method in the object.
Then it suddenly is passed by reference, otherwise it behaves as you'd
expect. (Note: it's PHP4, not 5. :)


------------------------------------------------------------------------

[2005-06-20 20:29:51] dmitry@php.net

PHP5 always pass and assign objects by reference.
You should set "zend.ze1_compatibility_mode=1" if you like PHP4
behavior.

------------------------------------------------------------------------

[2005-05-19 02:39:30] online at natweiss dot com

Description:
------------
See reproduce code.

php.ini is stock / no changes.

Reproduce code:
---------------
<?php
// a class that does nothing
class something{
	function nothing(){
		}
	}
// a pass-by-value function that modifies a member's member
function pass_by_value($value){
	$value->member->val = 1;
	}
// create a something with a member something
$object = new something;
$object->member = new something;

// call nothing, then call pass_by_value and print results
$object->member->nothing();
echo "member->val should be empty!\n";
pass_by_value($object);
print_r($object);
?>

Expected result:
----------------
$object->member should be empty

Actual result:
--------------
$object->member->val == 1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33061&edit=1


Thread (11 messages)

« previous php.bugs (#94359) next »