Re: New function proposal: spl_class_vars / params / contents
| From: | Nate Gordon | Date: | Wed, 21 Jan 2009 15:38:10 +0000 |
| Subject: | Re: New function proposal: spl_class_vars / params / contents | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42752@lists.php.net to get a copy of this message | ||
My personal favorite use of Reflection is Class Factories. While this
could be done with:
<?php
$className = 'Util';
$obj = new $className();
?>
It seems a little blunt to me, it also doesn't support having a
variable number of arguments to the constructor. I've seen some
pretty egregious hacks to make the above code work with a variable
number of arguments. I typically go for:
<?php
$ref = new ReflectionClass($className);
$obj = $ref->newInstanceArgs($args);
?>
It also seems like we have two different methods for accessing this
sort of information. Functions that are single purpose like
get_class_* and the Reflection interface. Saying that we have this
nice clean interface through reflection, but shouldn't use it because
no one wants to optimize it seems like a pretty thin argument.
On Wed, Jan 21, 2009 at 9:20 AM, Christian Schneider
<cschneid@cschneid.com> wrote:
> Nathan Rixham wrote:
>> seems to me that many of the new requests coming in, including my own
>> stupid ones are because people want to build fast decent orm's in php -
>
> Having built an ORM system myself I can say that you don't need
> Reflection (or even other fancy features not yet in PHP) for this.
>
> Maybe you are trying to use a hammer when the problem is not a nail,
> - Chris
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
-Nathan Gordon
If the database server goes down and there is no code to hear it, does
it really go down?
<esc>:wq<CR>