Behavior of References with Classes

From: Date: Sun, 17 Dec 2000 02:57:07 +0000
Subject: Behavior of References with Classes
Groups: php.general 
Request: Send a blank email to php-general+get-30700@lists.php.net to get a copy of this message
Somehow, the following lines from the PHP manual (http://www.php.net/manual/language.references.whatdo.php) seem really weirdio to me: "Note: Unless you use the syntax above, the result of $bar = new fooclass() will not be the same variable as $this in the constructor, meaning that if you have used reference to $this in the constructor, you should use reference assignment, or you get two different objects." What I don't understand is this: if references are simply supposed to create an alias to a variable's content... [ For example, the code... $foo = "you"; $bar = &$foo; ...means in memory you have a value "you" that can be accessed/modified with EITHER $foo or $bar.] ...then how does this end up creating multiple objects of the class? My apologies if I'm just stupid... it could be the wording that's confusing me or it could just be that I'm a confused individual to begin with :) I'm just looking for some help or maybe general discussion... anything to help get this straight in my head. :) Thanks all - Toby Butzon [ criticism spurs improvement ]

« previous php.general (#30700) next »