Re: Advantages of declared vs undeclared object properties

From: Date: Sun, 25 May 2008 19:39:44 +0000
Subject: Re: Advantages of declared vs undeclared object properties
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-274675@lists.php.net to get a copy of this message
On Sun, May 25, 2008 at 3:51 AM, Weston C <westonc@gmail.com> wrote: > In a setup like you've got with a SimpleXML object, where object > properties aren't necessarily declared in the class definition but are > added on an ad hoc basis, is there any performance hit? > > If not, other than the ability to mark properties as private, is there > any other particular advantage to declaring them at the top of the > class definition? its often quite helpful so that other developers, and even yourself know what exactly is going on inside a class. dynamically added variables are only visible at runtime, and therefore are difficult to understand during design time. SimpleXMLElement is exceptional, in that it has rather specialized semantics in terms of its interface. without such well defined semantics, imagine just adding and retrieving variables to an object, ad-hoc, all over the place; it could easily lead to a big mess. -nathan

« previous php.general (#274675) next »