Re: Re: function call chaining
| From: | Eddie Drapkin | Date: | Tue, 19 Jan 2010 16:20:02 +0000 |
| Subject: | Re: Re: function call chaining | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-46808@lists.php.net to get a copy of this message | ||
On Tue, Jan 19, 2010 at 11:05 AM, Stanislav Malyshev <stas@zend.com> wrote:
> The second was next on my list, while the first seems to me kind of exotic -
> why create object only to call one method and immediately drop it? Why this
> method is not static then?
Why would this imply "dropping" the object?
This:
$foo = (new bar())->someSetter();
Looks a lot better than this
$foo = new bar();
$foo->someSetter();
It's more obvious when you have to store your objects somewhere:
$foo->bar[$somevar] = (new bar())->someSetter();
Any object that returns $this a lot makes for a valid use case and
right now, we're forced to use a factory method hack, which doesn't
always work, especially in the cases where you have a dynamically
named class (and you can depend on inheritence to guarantee your
method, but not the existence of a static factory method).
What arguments are there against this? Why shouldn't it be allowed?