php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: online at natweiss dot com
New email:
PHP Version: OS:

 

 [2005-05-19 02:39 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-20 20:29 UTC] 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-06-21 18:21 UTC] 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. :)

 [2006-03-15 09:28 UTC] derick@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 05:01:28 2025 UTC