Return to Snippet

Revision: 7873
at August 19, 2008 14:11 by dvdrtrgn


Updated Code
<pre>

<?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);
?>


<hr>

The above example will output:

NULL
NULL
object(SimpleClass)#1 (1) {
   ["var"]=>
     string(30) "$assigned will have this value"
}
</pre>

Revision: 7872
at August 19, 2008 01:00 by dvdrtrgn


Initial Code
Example #6 Object Assignment
<?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);
?>
The above example will output:
NULL
NULL
object(SimpleClass)#1 (1) {
   ["var"]=>
     string(30) "$assigned will have this value"
}

Initial URL
http://us3.php.net/class

Initial Description
PHP: The Basics - Manual

Initial Title
Object Assignment

Initial Tags
php, object

Initial Language
HTML