|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33061 Pass object by value then modify initialized sub-object: passes by reference
Submitted: 2005-05-19 02:39 UTC Modified: 2006-03-15 09:28 UTC
From: online at natweiss dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 4CVS-2005-06-21 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: online at natweiss dot com
New email:
PHP Version: OS:


 [2005-05-19 02:39 UTC] online at natweiss dot com
See reproduce code.

php.ini is stock / no changes.

Reproduce code:
// 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
echo "member->val should be empty!\n";

Expected result:
$object->member should be empty

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-20 20:29 UTC]
PHP5 always pass and assign objects by reference.
You should set "zend.ze1_compatibility_mode=1" if you like PHP4 behavior.
 [2005-06-21 18:21 UTC]
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. :)

 [2006-03-15 09:28 UTC]
This patch (by dmitry) fixes it:

But we can not commit this as this might break backward compatibility, and we don't want to do that in PHP 4.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 16 19:03:35 2021 UTC