#49641 [NEW]: call-by-value does not work on objects
| From: | alhajaj at yahoo dot com | Date: | Wed, 23 Sep 2009 10:52:30 +0000 |
| Subject: | #49641 [NEW]: call-by-value does not work on objects | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-142761@lists.php.net to get a copy of this message | ||
From: alhajaj at yahoo dot com
Operating system: Windows XP
PHP version: 5.2.11
PHP Bug Type: Scripting Engine problem
Bug description: call-by-value does not work on objects
Description:
------------
when passing an object by value to a function it alters the original
object and not a copy of it. Here is a script to reproduce it. I included
the handling for passing strings which works as expected unlike passing
objects.
Reproduce code:
---------------
<?php
class User
{
var $name;
function User(){$this->name = "tony";}
}
function changeUserByRef(&$user) { $user->name = "changeUserByRef";}
function changeUserByValue($user) { $user->name = "changeUserByValue";}
function changeStringByRef(&$str) { $str = "changeStringByRef";}
function changeStringByValue($str) { $str = "changeStringByValue";}
$user = new User();
echo($user->name . '</br>' );
changeUserByRef($user);
echo("changeUserByRef = " . $user->name . '</br>' );
$user->name = "tony";
echo($user->name . '</br>' );
changeUserByValue($user);
echo("changeUserByValue = ". $user->name . '</br>' );
echo('<hr />');
$user->name = "tony";
echo($user->name . '</br>' );
changeStringByRef($user->name);
echo("changeStringByRef = " . $user->name . '</br>' );
$user->name = "tony";
echo($user->name . '</br>' );
changeStringByValue($user->name);
echo("changeStringByValue = " . $user->name . '</br>' );
?>
Expected result:
----------------
tony
changeUserByRef = changeUserByRef
tony
changeUserByValue = tony
---------------------------------------------------
tony
changeStringByRef = changeStringByRef
tony
changeStringByValue = tony
Actual result:
--------------
tony
changeUserByRef = changeUserByRef
tony
changeUserByValue = changeUserByValue
---------------------------------------------------
tony
changeStringByRef = changeStringByRef
tony
changeStringByValue = tony
--
Edit bug report at http://bugs.php.net/?id=49641&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49641&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49641&r=trysnapshot53
Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49641&r=trysnapshot60
Fixed in SVN: http://bugs.php.net/fix.php?id=49641&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49641&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=49641&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=49641&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=49641&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=49641&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=49641&r=support
Expected behavior: http://bugs.php.net/fix.php?id=49641&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=49641&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=49641&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=49641&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49641&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=49641&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=49641&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=49641&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=49641&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=49641&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=49641&r=mysqlcfg