Re: [PHP-DEV] [RFC] new foo()-bar()
2011/11/5 Stas Malyshev smalys...@sugarcrm.com: Hi! On 11/5/11 2:04 PM, Peter Cowburn wrote: Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? Bump. What's the current status on this? It would be nice to this teeny little patch in for 5.4.0 if possible. I think the brackets one is fine, if all the tests are OK we can have it in. But I'd like to get it before RC, after RC I don't want to have any substantial changes. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 Committed! -- Regards, Felipe Pena -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On 26 November 2010 19:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? Bump. What's the current status on this? It would be nice to this teeny little patch in for 5.4.0 if possible. -- Regards, Felipe Pena -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
Hi! On 11/5/11 2:04 PM, Peter Cowburn wrote: Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? Bump. What's the current status on this? It would be nice to this teeny little patch in for 5.4.0 if possible. I think the brackets one is fine, if all the tests are OK we can have it in. But I'd like to get it before RC, after RC I don't want to have any substantial changes. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
+1 for this there is a little worried about that, is changing %%expect okey? (of course I am not talking about that rewrite all the rules then fix the r/s conflicts) thanks On Sun, Nov 6, 2011 at 9:01 AM, Stas Malyshev smalys...@sugarcrm.com wrote: Hi! On 11/5/11 2:04 PM, Peter Cowburn wrote: Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? Bump. What's the current status on this? It would be nice to this teeny little patch in for 5.4.0 if possible. I think the brackets one is fine, if all the tests are OK we can have it in. But I'd like to get it before RC, after RC I don't want to have any substantial changes. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- Laruence Xinchen Hui http://www.laruence.com/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
Hi Dmitry, 2010/11/29 Dmitry Stogov dmi...@zend.com Hi Felipe, I'm wondered it works out of the box with so small patches :) However, both patches introduce new parser conflicts and it would be grate to avoid them. I will check if there is any way to avoid it. Also the patches need to be checked for memory leaks in case of exceptions thrown from constructor and chained function(s). Yes, I already did several tests to check this. It also probably makes sense to add array deference chaining e.g. new Foo()[] (just for language consistency). Hmm, looks good to me. :) Thanks. -- Regards, Felipe Pena
Re: [PHP-DEV] [RFC] new foo()-bar()
Care should be taken in the case of new myClass()-foo() just creates an object to call a method but a static method would be more efficient here. However, well used (fluent interface for exemple) make me think +1 for that patch. J.Pauli On Mon, Nov 29, 2010 at 12:40 PM, Felipe Pena felipe...@gmail.com wrote: Hi Dmitry, 2010/11/29 Dmitry Stogov dmi...@zend.com Hi Felipe, I'm wondered it works out of the box with so small patches :) However, both patches introduce new parser conflicts and it would be grate to avoid them. I will check if there is any way to avoid it. Also the patches need to be checked for memory leaks in case of exceptions thrown from constructor and chained function(s). Yes, I already did several tests to check this. It also probably makes sense to add array deference chaining e.g. new Foo()[] (just for language consistency). Hmm, looks good to me. :) Thanks. -- Regards, Felipe Pena -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
2010/11/29 Felipe Pena felipe...@gmail.com It also probably makes sense to add array deference chaining e.g. new Foo()[] (just for language consistency). Hmm, looks good to me. :) I've updated the patch with the bracketed version to include the array dereferecing support: http://felipe.ath.cx/diff/instance-method-call-3.patch ?php class foo extends ArrayObject { public function __construct($arr) { parent::__construct($arr); } } $arr = array(1, 2, 3); $value = (new foo($arr))[1]; // int(2) ? Some tests: http://felipe.ath.cx/diff/instance_direct_access_001.phpt -- Regards, Felipe Pena
Re: [PHP-DEV] [RFC] new foo()-bar()
On 27 November 2010 03:36, Felipe Pena felipe...@gmail.com wrote: I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Thoughts? Great work, Felipe! +1 for the feature; my very weak preference would be for the explicitly bracketed version, but I'd be happy with either. Adam -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
Hi Felipe, I'm wondered it works out of the box with so small patches :) However, both patches introduce new parser conflicts and it would be grate to avoid them. Also the patches need to be checked for memory leaks in case of exceptions thrown from constructor and chained function(s). It also probably makes sense to add array deference chaining e.g. new Foo()[] (just for language consistency). Thanks. Dmitry. On 11/26/2010 10:36 PM, Felipe Pena wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
Hi, 2010/11/26 Felipe Pena felipe...@gmail.com 2010/11/26 Johannes Schlüter johan...@schlueters.de On Fri, 2010-11-26 at 17:36 -0200, Felipe Pena wrote: var_dump(new foo()-bar()-x); // string(3) PHP It has some readability issues. One might assume it is new (foo()-bar()-x) not (new foo())-bar()-x As there is a mandatory space between new and its operand and no space in front of the object operator and we allow non-constant operands to new. So what is new $bar-foo(); ? If I read the patch correctly this is valid and evaluated as (new $bar)-foo(); johannes new foo()-bar() should be read as: (new foo())-bar(). And using variable: new $bar-y()-x should be read as: (new ($bar-y)())-x. ?php class foo { public $x = 1; } class bar { public $y = 'foo'; } $bar = new bar; var_dump(new $bar-y()-x); // 1 ? I.e. just as it is nowdays. Well, if this feature is going to be accept, we could to decide what syntax to use. I have created another patch which is the bracketed version of this presented here. ?php class foo { public $x = 1; } class bar { public $y = 'foo'; } $x = 'bar'; $bar = new bar; var_dump((new bar)-y); // foo var_dump((new $x)-y); // foo var_dump((new $bar-y)-x); // 1 ? Thus we do not have the readability issues, as pointed by Johannes. http://wiki.php.net/rfc/instance-method-call (updated!) Thanks for the comments. -- Regards, Felipe Pena
[PHP-DEV] [RFC] new foo()-bar()
Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- Regards, Felipe Pena
Re: [PHP-DEV] [RFC] new foo()-bar()
+1 Seems like a handy change and the patch is quite manageable. On Fri, Nov 26, 2010 at 2:36 PM, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- Regards, Felipe Pena -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, Nov 26, 2010 at 14:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? I'm all for it, Felipe. Chaining like that would really come in handy in several situations of which I can think right off the top of my head even. -- /Daniel P. Brown Network Infrastructure Manager Documentation, Webmaster Teams http://www.php.net/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, 2010-11-26 at 17:36 -0200, Felipe Pena wrote: var_dump(new foo()-bar()-x); // string(3) PHP It has some readability issues. One might assume it is new (foo()-bar()-x) not (new foo())-bar()-x As there is a mandatory space between new and its operand and no space in front of the object operator and we allow non-constant operands to new. So what is new $bar-foo(); ? If I read the patch correctly this is valid and evaluated as (new $bar)-foo(); johannes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, Nov 26, 2010 at 8:36 PM, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- Regards, Felipe Pena I like it, and it is a good pair with the new array dereferencing, so hopefully I don't have to create temp variables anymore \o/ Tyrael
Re: [PHP-DEV] [RFC] new foo()-bar()
On 26 November 2010 20:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. That means you don't actually need the object at all, you should probably be looking for static methods or class properties. Trying to avoid statics by introducing a way to instantiate and throw away objects in the same statement feels a lot like reinventing OOP while adding overhead. Anyway, just a personal observation. I generally favour the way that PHP allows you to dig your own grave (i.e. I love the freedom of the language), so as a developer I would probably favour this as well, though I find it mainly a way to introduce hacks. Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, Nov 26, 2010 at 9:25 PM, Peter Lind peter.e.l...@gmail.com wrote: On 26 November 2010 20:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. That means you don't actually need the object at all, you should probably be looking for static methods or class properties. Trying to avoid statics by introducing a way to instantiate and throw away objects in the same statement feels a lot like reinventing OOP while adding overhead. Anyway, just a personal observation. I generally favour the way that PHP allows you to dig your own grave (i.e. I love the freedom of the language), so as a developer I would probably favour this as well, though I find it mainly a way to introduce hacks. 1, I have to use a non-trivial library or module for a simple task, and I don't want to write 20 line of code, and introduce 4 helper variable. 2. I want to get from point 1 to point 5 but I'm not interested in the steps in-between (classical method chaining), but sadly one of the steps requires object instantiation. Tyrael
Re: [PHP-DEV] [RFC] new foo()-bar()
On 26 November 2010 21:37, Ferenc Kovacs i...@tyrael.hu wrote: On Fri, Nov 26, 2010 at 9:25 PM, Peter Lind peter.e.l...@gmail.com wrote: On 26 November 2010 20:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. That means you don't actually need the object at all, you should probably be looking for static methods or class properties. Trying to avoid statics by introducing a way to instantiate and throw away objects in the same statement feels a lot like reinventing OOP while adding overhead. Anyway, just a personal observation. I generally favour the way that PHP allows you to dig your own grave (i.e. I love the freedom of the language), so as a developer I would probably favour this as well, though I find it mainly a way to introduce hacks. 1, I have to use a non-trivial library or module for a simple task, and I don't want to write 20 line of code, and introduce 4 helper variable. If it's a one-off, then I really don't see the problem. If you're facing it again, write a facade. 2. I want to get from point 1 to point 5 but I'm not interested in the steps in-between (classical method chaining), but sadly one of the steps requires object instantiation. If it's your code, then why are you not simplifying it? What's the point of writing code that you have to go through in five steps? Why not write a wrapper method? The reasons presented sounds quite like I want to be able write hacks easier rather than I want to fix an actual problem. I.e. there are solutions for this already that use OOP principles. That said, this fix may very well address other situations :) Regards Peter -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
2010/11/26 Johannes Schlüter johan...@schlueters.de On Fri, 2010-11-26 at 17:36 -0200, Felipe Pena wrote: var_dump(new foo()-bar()-x); // string(3) PHP It has some readability issues. One might assume it is new (foo()-bar()-x) not (new foo())-bar()-x As there is a mandatory space between new and its operand and no space in front of the object operator and we allow non-constant operands to new. So what is new $bar-foo(); ? If I read the patch correctly this is valid and evaluated as (new $bar)-foo(); johannes new foo()-bar() should be read as: (new foo())-bar(). And using variable: new $bar-y()-x should be read as: (new ($bar-y)())-x. ?php class foo { public $x = 1; } class bar { public $y = 'foo'; } $bar = new bar; var_dump(new $bar-y()-x); // 1 ? I.e. just as it is nowdays. -- Regards, Felipe Pena
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, Nov 26, 2010 at 9:46 PM, Peter Lind peter.e.l...@gmail.com wrote: On 26 November 2010 21:37, Ferenc Kovacs i...@tyrael.hu wrote: On Fri, Nov 26, 2010 at 9:25 PM, Peter Lind peter.e.l...@gmail.com wrote: On 26 November 2010 20:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. That means you don't actually need the object at all, you should probably be looking for static methods or class properties. Trying to avoid statics by introducing a way to instantiate and throw away objects in the same statement feels a lot like reinventing OOP while adding overhead. Anyway, just a personal observation. I generally favour the way that PHP allows you to dig your own grave (i.e. I love the freedom of the language), so as a developer I would probably favour this as well, though I find it mainly a way to introduce hacks. 1, I have to use a non-trivial library or module for a simple task, and I don't want to write 20 line of code, and introduce 4 helper variable. If it's a one-off, then I really don't see the problem. If you're facing it again, write a facade. 2. I want to get from point 1 to point 5 but I'm not interested in the steps in-between (classical method chaining), but sadly one of the steps requires object instantiation. If it's your code, then why are you not simplifying it? What's the point of writing code that you have to go through in five steps? Why not write a wrapper method? The reasons presented sounds quite like I want to be able write hacks easier rather than I want to fix an actual problem. I.e. there are solutions for this already that use OOP principles. Sorry, I don't have the time and/or patience to fix every code out there, which I might happen to come across in a project. :) That said, this fix may very well address other situations :) sure thing, I just told a(two) use-case from the top of my head. Tyrael
RE: [PHP-DEV] [RFC] new foo()-bar()
November-26-10 2:36 PM, Felipe Pena writes: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? Nice. I have use for this. Some readability issues may arise but nothing that can't be overcome with some common sense. Best Regards, Mike Robinson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On 11/26/2010 2:36 PM, Felipe Pena wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? I fully support this patch. This is something PHP has needed for a long time. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, 26 Nov 2010 20:25:32 -, Peter Lind peter.e.l...@gmail.com wrote: It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. Not necessarily; you could be calling the method for the collateral effects and that method return the object itself. This is not that uncommon. +1 -- Gustavo Lopes -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Friday, November 26, 2010, Gustavo Lopes glo...@nebm.ist.utl.pt wrote: On Fri, 26 Nov 2010 20:25:32 -, Peter Lind peter.e.l...@gmail.com wrote: It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. Not necessarily; you could be calling the method for the collateral effects and that method return the object itself. This is not that uncommon. And I can do that today with a factory pattern, if I want to. Anyway, I don't want to argue against the feature, as it will just introduce a slightly shorter version of something we can already do. -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Fri, Nov 26, 2010 at 2:36 PM, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- Regards, Felipe Pena Felipe, you're on a roll :) It's great! Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP-DEV] [RFC] new foo()-bar()
+1 Good job felipe On 26 November 2010 14:36, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- Regards, Felipe Pena
Re: [PHP-DEV] [RFC] new foo()-bar()
Hi Felipe 2010/11/26 Felipe Pena felipe...@gmail.com: Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? huge +1 from me ;-) It might be worth adding function call chaining with dereferencing and instance method call chaning, like $a = function(){ return function(){ echo 'Hello'; }; }; $a()(); -- regards, Kalle Sommer Nielsen ka...@php.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
Hi! huge +1 from me ;-) It might be worth adding function call chaining with dereferencing and instance method call chaning, like $a = function(){ return function(){ echo 'Hello'; }; }; $a()(); See: http://wiki.php.net/rfc/fcallfcall -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
+1 :) On Fri, Nov 26, 2010 at 8:36 PM, Felipe Pena felipe...@gmail.com wrote: Hi all, I'm here again to presents another proposal, which adds support for instantiating a class and calling its methods and accessing its properties on same command. Example: ?php class bar { public $x = 'PHP'; } class foo extends bar { public function bar() { return $this; } } var_dump(new foo()-bar()-x); // string(3) PHP ? Other examples which describes the feature at http://wiki.php.net/rfc/instance-method-call Thoughts? -- Regards, Felipe Pena -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] [RFC] new foo()-bar()
On Friday, November 26, 2010, Gustavo Lopes glo...@nebm.ist.utl.pt wrote: On Fri, 26 Nov 2010 20:25:32 -, Peter Lind peter.e.l...@gmail.com wrote: It seems fairly handy and I've been in situations where I wanted to do something like that - in fact, I use factories to achieve something similar. However, the more I use it, the more it feels like introducing code smells into my code. You're essentially instantiating an object only to immediately throw it away. Not necessarily; you could be calling the method for the collateral effects and that method return the object itself. This is not that uncommon. And I can do that today with a factory pattern, if I want to. Anyway, I don't want to argue against the feature, as it will just introduce a slightly shorter version of something we can already do. -- hype WWW: plphp.dk / plind.dk LinkedIn: plind BeWelcome/Couchsurfing: Fake51 Twitter: kafe15 /hype -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php