Hi,

On Tue, 2007-10-02 at 15:54 +0200, Sebastian Bergmann wrote:
> Guilherme Blanco schrieb:
> > Altho I found this idea really interesting, I have a suggestion for
> > it. Instead of use a function to handle new overloads, I suggest a
> > magic method, something like __new.
> 
>  __new() was what I initially proposed to Johannes but IIRC there were
>  some performance implications with that. Johannes?

The initial implementation Sebastian refers to is a conference hack I
did, which was done to see whether it's possible and give Sebastian a
thing to test the feature - there wasn't much thinking involved :-)

For an extension, which the current implementation is, using the
register function is the best approach I see. Else we would have to to
the look-up for the __new() function on every object instantiation. The
existence of that function can't be cached since it could be defined any
time. (While for an extension, used for testing, performance is not #1
prio)

If such an feature would become an engine feature one could cache the
declaration of __new() during the function declaration - which in that
case would, indeed, be the best.

But all that are implementation details. The question is: Do we need
such a feature inside Core PHP or is an extension overloading ZEND_NEW
enough?

The only need I see is mocking objects for a unit test. This is usually
done on a test system so installing such an extension shouldn't be to
hard (especially for somebody who is able to do unit tests using mock
objects...)

One might also think about taking XDebug's code coverage stuff and the
ZEND_NEW overloading and other stuff to build a phpunit extension - but
that's no topic for internals :-)

johannes

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to