Re: Get name of extending class with static method call (PHP5)

From: Date: Wed, 12 Jan 2005 19:39:48 +0000
Subject: Re: Get name of extending class with static method call (PHP5)
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-14366@lists.php.net to get a copy of this message
"Christian Schneider" <cschneid@cschneid.com> wrote in message news:41E5790D.2090402@cschneid.com... > Torsten Roehr wrote: > > Something so straightforward and fundamental should be possible!?! > > Maybe is isn't as fundamental as you think? I never came across this > problem in years of PHP programming. But then again I use classes with > static calls for nothing but separate namespaces :-) > > I'm pretty sure there is another (possibly more elegant) solution. This > is not a flame but a suggestion to rethink the problem you are trying to > solve. > > - Chris Hi Chris, no problem - not feeling flamed here ;) Maybe I should elaborate a bit more what I'm needing this for. I would like to write a load method in a superclass that can be used by all subclasses. I'm just passing in the SQL statement as a parameter. The load method commits the query, loops through the result set and creates/returns a collection of objects. The method needs to know the name of the class to create objects of this class. Example: $persons = Person::load($sql); // returns collection of Person objects $cars = Car::load($sql); // returns collection of Car objects All classes can use the same load method and the database access (for selects) is only needed in this method and can therefore be changed easily. It's a bit simplified but I hope you get the idea. Also from the heated discussion on php-general you can see that there are quite a few people facing the described problem. Best regards, Torsten Roehr

« previous php.internals (#14366) next »