Re: Class Posing

From: Date: Tue, 02 Oct 2007 16:53:16 +0000
Subject: Re: Class Posing
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-32558@lists.php.net to get a copy of this message
Earlier this year, Johannes implemented class posing for PHP as follows: <?php class Foo {} class Bar extends Foo {} function new_overload($className) {
       if ($className == 'Foo') {
           return new Bar;
       }
       // ...
} $o = new Foo; // $o is an object of Foo. register_new_overload('new_overload'); $o = new Foo; // $o is an object of Bar. ?>
This looks like factory pattern. What's wrong with implementing it as factory?
However, to make this a viable mechanism that can be used in tools such as PHPUnit (for which I could really use this functionality), we agreed that it actually belongs into the core.
I personally don't see much of the use of it in the core, and it definitely adds very "magic" things - you don't know anymore what class you are instantiating when you run "new Foo". My opinion is it belongs to places like "runkit" which do tricks with the language, but I don't see much use for it in the core. Could you explain more why existing pattern won't work for the same? -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

« previous php.internals (#32558) next »