Re: How can I do this -- method chaining
| From: | Stut | Date: | Wed, 30 Jan 2008 00:27:45 +0000 |
| Subject: | Re: How can I do this -- method chaining | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268294@lists.php.net to get a copy of this message | ||
On 29 Jan 2008, at 20:08, "Nathan Nobbe" <quickshiftin@gmail.com> wrote:
On Jan 29, 2008 3:02 PM, Stut <stuttle@gmail.com> wrote: Why? What exactly do you think you're saving by not putting the instance in a variable? I can't think of one good reason to do this. its an esthetic thing; and besides the simple factory method is an easy workaround to achieve it. as the article that, Eric, posted mentioned, other languages have such support; ie javascript: function Test() {} Test.prototype = { doSomething : function() { alert('hello'); } } new Test().doSomething(); this is along the lines of the whole returnAnArray()['someIndex'] thing, fortunately in this case, theres a workaround in userspace ;)I don't see how it's any more aesthetically pleasing, but each to their own I guess. Personally I'd use a static method in this instance. If you need to create an instance of the class you can do so in the static method and that way it will get destroyed when the function is done. Otherwise the object scope is far larger than it needs to be, which IMHO is an unnecessary waste of resources and certainly less aesthetic. -Stut -- http://stut.net/