[PHP] Re: New object model
Troy S wrote: Is there an ini-file setting so that objects are passed by value as in PHP 4? If so, how long is this likely to be supported? Thanks, Troy Although you can turn on zend engine 1 compatibility, if you intend to distribute your code you cannot expect this on most servers. Another way to pass by value is to use the __clone method. function test($orig, $clone) { $orig-x = 'I am the original.'; $clone-x = 'I am a clone.'; print_r($orig); // should be different since this is a copy, not a reference print_r($clone); } class foo {} $orig = new foo(); test($orig, $orig-__clone()); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: New object model
Jason Barnett wrote: Although you can turn on zend engine 1 compatibility, if you intend to distribute your code you cannot expect this on most servers. Another way to pass by value is to use the __clone method. function test($orig, $clone) { $orig-x = 'I am the original.'; $clone-x = 'I am a clone.'; print_r($orig); // should be different since this is a copy, not a reference print_r($clone); } class foo {} $orig = new foo(); test($orig, $orig-__clone()); Fatal error: Cannot call __clone() method on objects - use 'clone $obj' instead... Should be: test($orig, clone($orig)); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: New object model
Troy S wrote: Is there an ini-file setting so that objects are passed by value as in PHP 4? If so, how long is this likely to be supported? I believe this is possible with the following setting in php.ini: zend.ze1_compatibility_mode = On This should turn on PHP5's backwards compatibility with PHP4 (meaning that the objects are passed by value instead of by reference... the old way). -- Regards, Ben Ramsey http://benramsey.com --- http://www.phpcommunity.org/ Open Source, Open Community Visit for more information or to join the movement. --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php