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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
48 - 20 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 05:01:29 2024 UTC