Re: PHP 6.0 Wishlist
| From: | Andi Gutmans | Date: | Wed, 24 Aug 2005 23:01:22 +0000 |
| Subject: | Re: PHP 6.0 Wishlist | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-18385@lists.php.net to get a copy of this message | ||
Well $proxy would automagically support the interfaces of the aggregated objects. And if there's a method you want to proxy to one rather the other you could fine tune that. Anything more than that would be getting into an OOP pissing contest which I don't feel like getting into, as it would be academic and wouldn't be suitable for the PHP audience...
Andi
At 03:43 PM 8/24/2005, Marcus Boerger wrote:
Hello Andi, hu? Here's you example again: <?php $proxy = new Proxy() $proxy->aggregate($obj2); /* Also aggregates interfaces */ $proxy->aggregate($obj3); $proxy->delegate($obj3, "method_that_exists_in_both_objects"); ?> ok lets change this to an interface like in my example: <?php interface Printable { function print(); } class Document extends Proxy implements Printable { // now you need to implement the functions of Printable, only how? // implement them as empty and later overload them with their real body? } ?> So what do you want to do about the fact that my delegates are done at compile time while your aggregation is run at compile time? And no, at the moment there is absolutley no way than to completley rewrite the object/interface stuff in php to allow dynamic interfaces which your proposal would need become compatible. And even if you did you'd simply overthrow the idea of interfaces, wouldn't you? best regards marcus Thursday, August 25, 2005, 12:35:11 AM, you wrote: Not if it's done they way I think it can be done... At 03:17 PM 8/24/2005, Marcus Boerger wrote:It simply isHello Andi, you mean fine tune the 'protocol' to use the correct wording.proxy/aggregation ideaincompatible with the interface concept. Wednesday, August 24, 2005, 11:48:33 PM, you wrote:I don't mind not adding it, as long as we don't add "delegate" :) Anyway, it's different from MI because it allows you to fine tune the interface... AndiAt 12:01 PM 8/24/2005, Marcus Boerger wrote:Hello Andi, i said 'we could probably add'. But even thoughthat time welike you offered and which i of course could implement in spl exists i still see no reason for it. The problem with the latter is that it only gives you back the original MI problems and doesn't work together with interfaces at all. Thus i see it as contraproductive. Or in other words let's simply not add something here and live with code reuse. Unless it turns out in the future that it becomes the normal thing - byin PHP 6 or 7Again (I sound like a broken record), I don't think that we should add language constructs to support delegation. We will be overcomplicating things for PHP developers and it'll start to be hard to read PHP code. I do think it might be worth considering a user-land or internal class such as a Proxy class which would allow the advanced user to have more find-grained control on delegation. I'd still keep it simple. So basically I'd allow aggregating objects (or delegatees), and define their priority in the order they are added. Then there could be one method which overrides this priority by allowing to map methods to objects. For example something like:might have PHP 8 wishlist ;-) regards marcus Wednesday, August 24, 2005, 1:27:20 AM, you wrote:$proxy = new Proxy() $proxy->aggregate($obj2); /* Also aggregates interfaces */ $proxy->aggregate($obj3); $proxy->delegate($obj3, "method_that_exists_in_both_objects");This would only be used in very advanced cases, most probably in frameworks but would be invisible to the average PHP developer. Complicating it more than this including the addition of language constructs doesn't seem good to me. If this isn't enough (and I"m sure there are some hypothetical cases where it might not be), then you could achieve the same goal in other ways...Still I am torn wether even this should be added. Andi At 12:57 PM 8/23/2005, Marcus Boerger wrote:At 19:12 23/08/2005, Lukas Smith wrote:Hello Zeev, Tuesday, August 23, 2005, 8:59:49 PM, you wrote:future version.Joseph Crawford wrote:I would like to see Multiple Inheritance implemented in aimplementingI am not sure what obstacles got in the way (if any) for notthat in PHP 5 but i would defenately like to see thatimpl for theYou're right, it was, that's why we have interfaces.similar effects.IIRC, it was shot down. Use overloading and interfaces to getthis is theExactly. And you can emulate MI with __call(). The only thing we could probably add is delegates to overcome the anti-code-reuse interface aspect. // Some interface interface Printable { function print(); } // A general implementation for the interface class PrintHandler implements Printable { function print() { /* ... */ } } // A standard user class that implements the interface. Typically// reason for MI since often you would just go with a standardOn the otheris an error// interfaced code. Actually common with containers (*). class Document implements Printable { delegate Printable $print; function __construct() {$this->print = new PrintHandler($this);} // No need to provide function print here - actually doing sothe delegate:// since tit's body is automatically generated as a call tobe NULL");// function print() { // if (!$this->print) throw new Exception("Delegate must not// $this->print->print(); // } } On the one hand this raises the complexity and syntax magic.otherwise a painway it is really elegant and promotes code-reuse which isit againa andbase classwith interfaces. (*) Actually the most prominent case is a general Container and acontainers too. Soin a GUI Framwork. There the desktop and the windows needyou'd habe an interface to access the container and implementmistake - nobodyagain...even though you already have it. And if you find atells you whether you fixed all incarnations of the code.