note 10041 modified in Classes and Objects by zak
| From: | zak@php.net | Date: | Sat, 09 Dec 2000 11:26:17 +0000 |
| Subject: | note 10041 modified in Classes and Objects by zak | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-8548@lists.php.net to get a copy of this message | ||
# Editor's Note
# Do not do this!
# When you call an object's constructor from
# within the constructor, you are creating an
# infinite loop. An attempt to instantiate the
# object results in another attempt to instantiate
# the object, which results in another ...
Has anyone else encountered a problem when you call an object's constructor from within the
same constructor? I have an object with one of it's member variables acting as a pointer to
another object of the same type. When I try to initialize it within the constructor, I just get
what I guess is a trashed response from the server (with no clue as to what the error was, causing
hours wasted away in trying to hunt it down.
Here is a code example:
class Object {
.
public Object() {
.
this.object = new Object();
}
This causes everything to blow up.
http://www.php.net/manual/classes-and-objects.php