Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45974 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89943 invoked from network); 8 Nov 2009 09:23:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Nov 2009 09:23:32 -0000 X-Host-Fingerprint: 95.31.13.88 xdmitri2.static.corbina.ru Received: from [95.31.13.88] ([95.31.13.88:22979] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/70-21516-11E86FA4 for ; Sun, 08 Nov 2009 04:23:30 -0500 Message-ID: <56.70.21516.11E86FA4@pb1.pair.com> To: internals@lists.php.net References: <0F.F6.03668.AD206FA4@pb1.pair.com> Date: Sun, 8 Nov 2009 12:23:24 +0300 Lines: 66 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5843 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-RFC2646: Format=Flowed; Response X-Posted-By: 95.31.13.88 Subject: Re: [PHP-DEV] Regarding constructions like func()[0] From: dmda@yandex.ru ("jvlad") ""melfar"" wrote in message news:0F.F6.03668.AD206FA4@pb1.pair.com... > Hey, > > Yep, I think there might be some caveats to that change. > The original patch did not work on methods, so I've fixed that and also > made the return value an rvalue, so that you can't attempt to modify the > temporary value, the zend_check_writable_variable guard will yield an > error. > > The updated patch can be found at http://bugs.php.net/bug.php?id=50003 > > I've also heard an opinion that adding this construction is just going to > make things more > complicated, but take this: chained -> operators are supported for return > values and I'm only seeing code getting simpler because of that. > > Br, > -melfar - the patch introduces 5 more grammar conflicts. Did you check them all? - can't call the results useful. Instead of returning possibly long array and fetching just one element, why not to add an argument to the funtion - the index of the element to be returned? - if you badly need the "function" returning an array and you prefer syntax to performance, think about indexed class property implemented via setters/getters: class A { public function __get($prop) { if ($prop == "b") return array('a' => 'b'); } } $a = new A(); echo $a->b['a']; Class instance is where you'll keep the context. If you don't need any context, static properties would be useful, but they can't be implemented via setters/getters and this is a thing should be changed in order to get the following sample working: 'b'); } } echo A::$b['a']; ?> I think php is not that bad after all :) just 2c.