note 53772 deleted from language.oop5.basic by colder
| From: | colder@php.net | Date: | Sun, 19 Aug 2007 23:40:56 +0000 |
| Subject: | note 53772 deleted from language.oop5.basic by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129611@lists.php.net to get a copy of this message | ||
Note Submitter: jerry
----
Note the little correction on graced's notes below:
Your explanation looks correct about how instances created and destroyed, just wanted to correct
some errors in your code below. But Thank you greatly for explaining that I appreciate it.
<?php
$obj1 = new stdclass();
var_dump($obj1); // object #1
$obj1 = new stdclass();
var_dump($obj1); // object #2
// no more references to object #1, so it is destroyed.
$obj1 = new stdclass(); // object #1 (object #2 destroyed right after this expression)
var_dump($obj1);
$obj2 = $obj1; // two variables now reference object #1
$obj1 = new stdclass(); // becomes object #2
var_dump($obj1);
$obj1 = new stdclass(); // object #3
var_dump($obj1);
?>
Output:
object(stdClass)#1 (0) {
}
object(stdClass)#2 (0) {
}
object(stdClass)#1 (0) {
}
object(stdClass)#2 (0) {
}
object(stdClass)#3 (0) {
}