Date: 08/22/01
- Next message: Jeremy Bettis: "[PHP-DEV] object to string convertion patch"
- Previous message: alberty <email protected>: "[PHP-DEV] Bug #12894 Updated: GD crashes PHP by using GD Format"
- In reply to: olli <email protected>: "[PHP-DEV] Bug #12905: "return" returns a copy of an object instead of a reference"
- Next in thread: jeroen <email protected>: "[PHP-DEV] Bug #12905 Updated: "return" returns a copy of an object instead of a reference"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
ID: 12905
User updated by: olli <email protected>
Reported By: olli <email protected>
Status: Open
Old Bug Type: Scripting Engine problem
Bug Type: Documentation problem
Operating System: Slackware 7
PHP Version: 4.0.6
New Comment:
renaming the function:
function AddChild(...
to
function &AddChild(...
makes return return by reference instead of by value, i didnt think to do this so it appears its my fault:)
i've changed this bug to a documentation problem tho cos i cant find any reference to this in the docs.
Previous Comments:
------------------------------------------------------------------------
[2001-08-22 12:13:08] olli <email protected>
<?
Class ChildClass {
var $value;
function ChildClass($value){
$this->value = $value;
}
}
Class ParentClass {
var $children;
function ParentClass(){
$this->children = array();
}
function AddChild($value){
$child = &new ChildClass($value);
array_push($this->children, &$child);
return $child;
}
}
$p1 = &new ParentClass();
$c1 = &$p1->AddChild('set in constructor');
$c1->value = 'set elsewhere';
echo "the reference to the object created in AddBand and stored in the parentclass' array is different to that returned by the AddBand function<br>";
echo $p1->children[0]->value."<br>";
echo $c1->value;
?>
"return" is returning a copy of the object created in parentclass->AddChild instead of a reference. "return &$object" is flagged as invalid by the php interpreter.
thanks a lot
olli holliday
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=12905&edit=1
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Jeremy Bettis: "[PHP-DEV] object to string convertion patch"
- Previous message: alberty <email protected>: "[PHP-DEV] Bug #12894 Updated: GD crashes PHP by using GD Format"
- In reply to: olli <email protected>: "[PHP-DEV] Bug #12905: "return" returns a copy of an object instead of a reference"
- Next in thread: jeroen <email protected>: "[PHP-DEV] Bug #12905 Updated: "return" returns a copy of an object instead of a reference"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

