|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-02 12:22 UTC] rejek at sdnet dot pl
Description: ------------ Look at the Ex. 19-4 in polish ver. of documentation avaible to download at http://pl2.php.net/get/php_manual_pl.html.gz/from/pl.php.net/mirror The line "$instance->var = '$assigned will have this value';" should be just after "<?PHP" tag to get the expected result given in the box under ex. code. I don't know how it looks in other language versions. Brgs Mateusz Rejek Reproduce code: --------------- <?php $assigned = $instance; $reference =& $instance; $instance->var = '$assigned will have this value'; $instance = null; // $instance and $reference become null var_dump($instance); var_dump($reference); var_dump($assigned); ?> Expected result: ---------------- NULL NULL object(stdClass)#1 (1) { ["var"]=> string(30) "$assigned will have this value" } Actual result: -------------- NULL NULL NULL PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 10:00:01 2025 UTC |
If the example was ... [code] <?php class SimpleClass { // member declaration public $var = 'a default value'; // method declaration public function displayVar() { echo $this->var; } } $instance = new SimpleClass(); $assigned = $instance; $reference =& $instance; $instance->var = '$assigned will have this value'; $instance = null; // $instance and $reference become null var_dump($instance); var_dump($reference); var_dump($assigned); ?> [/code] Then that would be more meaningfull. The documented example assumes that you are using the simple class and that you have created an instance of it. Without that the output is just junk. E.g. C:\>php <?php class SimpleClass { // member declaration public $var = 'a default value'; // method declaration public function displayVar() { echo $this->var; } } $instance = new SimpleClass(); $assigned = $instance; $reference =& $instance; $instance->var = '$assigned will have this value'; $instance = null; // $instance and $reference become null var_dump($instance); var_dump($reference); var_dump($assigned); ?> ^Z NULL NULL object(SimpleClass)#1 (1) { ["var"]=> string(30) "$assigned will have this value" } C:\>