Re: Re: Why is it possible to assign data to _not_declared_ vars in a class (PHP 5.0.3)?

From: Date: Sat, 09 Apr 2005 19:02:08 +0000
Subject: Re: Re: Why is it possible to assign data to _not_declared_ vars in a class (PHP 5.0.3)?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-212740@lists.php.net to get a copy of this message
* Hanez <mailman@hanez.org>: > On Friday 08 April 2005 20:22, Matthew Weier O'Phinney wrote: > > * Johannes Findeisen <mailman@hanez.org>: > > > If i understand right, all variables should be declared in PHP5. So > > > why is it possible to add a membervariable called "c" to the object > > > without making a declaration? I got no error with this. I thought > > > E_STRICT should show me things like that. Could someone explain me > > > that? > > > > You don't understand correctly. Class properties/attributes do not need > > to be explicitly declared in PHP. This did *not* change in PHP5. What > > changed in PHP5 is visibility. By default, unless declared otherwise, a > > class attribute is publicly visible -- the same behaviour seen in PHP4. > > Okay, allright. I missunderstood that. But wouldn't it be nice to see things > like this in the error log when E_STRICT is activated. I know some > programming languages and i ever have dreamed about some features like this > in PHP5 and the main thing i was dreaming about was strict declaration. Now > since PHP5 i have thought about programming PHP again because of features > which would help me debugging my code. And this is not implemented perfectly. E_STRICT doesn't catch it because it's not considered bad behaviour; this is perfectly legal behaviour according to the PHP parser. PHP doesn't have the same scoping issues as, say, Perl. Variables in PHP do *not* need to be pre-declared (though testing for a value on an undeclared variable, be it in a class or otherwise, *will* generate an E_NOTICE). This is a *difference* in PHP from other languages, and likely exists for a reason. If you want to know why it exists that way, or feel it should be changed, you should probably go over to the php-dev list. -- Matthew Weier O'Phinney | WEBSITES: Webmaster and IT Specialist | http://www.garden.org National Gardening Association | http://www.kidsgardening.com 802-863-5251 x156 | http://nationalgardenmonth.org mailto:matthew@garden.org | http://vermontbotanical.org

« previous php.general (#212740) next »