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:
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC