Re[2]: [PHP] declaring variables in class definitions

From: Date: Wed, 10 Jan 2001 17:43:04 +0000
Subject: Re[2]: [PHP] declaring variables in class definitions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33714@lists.php.net to get a copy of this message
Hello sam1600, Wednesday, January 10, 2001, 7:44:44 PM, you wrote: >> $d->somevar = true; >> and the next call to $d->b() will print nothing. >> But you won't be able to assign a value to $somevar, if it is not >> declared in the class. sic> This does not appear to be true. With error reporting set to max, and the sic> variables not defined in the class ( $somevar,$somevar2 and $somevar3 ), sic> the following will echo out: sic> Not set sic> empty sic> value of somevar2 sic> value of somevar3 sic> class a { sic> function b(){ sic> if (!isset($this->somevar)) sic> echo "Not set<br>"; sic> if (empty($this->somevar)) sic> echo "empty<br>"; sic> } sic> } sic> $d = new a; $d->b(); $d->somevar2 = "value of somevar2<br>"; $d->somevar3 = "value of somevar3<br>"; echo $d->somevar2; echo $d->somevar3; try to assign something to $d->somevar if it is not declared in the definition. >> the method b() of the class a will break if you don't declare $somevar >> in the class definition. In the string "if (!isset($this->somevar))" >> it would throw an error saying that you have no variable named 'somevar' in >> you class. sic> This does not appear to be true either, see above. bad practice anyway -- Best regards, Max A. Derkachev mailto:kot@books.ru Symbol-Plus Publishing Ltd. phone: +7 (812) 324-53-53 http://www.Books.Ru -- All Books of Russia  

« previous php.general (#33714) next »