Re: Closures and $this

From: Date: Fri, 20 Nov 2009 07:10:01 +0000
Subject: Re: Closures and $this
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-46121@lists.php.net to get a copy of this message
Hi > so you can with $foo->$bar() or $foo() You're talking about variable functions/methods. But that is not the subject of discussion. Variable functions/methods are useful but introduce mess. This is well-known and this feature exists in PHP for a long time - so everybody should be condidered as warned - when they use it. I am talking about $this->methodName() constructions. Currently, in PHP, one can be pretty sure that if this construction works in one place - it should work in another (I mean, methodName() will exist in $this). To be mentioned - I'm not using variable functions here. 2009/11/19 Stanislav Malyshev <stas@zend.com>: > Hi! > >> If php-people really would like rebinding $this, I beleive this should >> be done via method like Closure->bindTo() - to make the fact of >> rebinding clear in the code. >> >> However, there is a problem with rebinding $this - that was not >> mentioned yet, I think. > > This can be a problem, but since PHP is not a compiled language, this > problem already exists - all method names are only checked in runtime > anyway, so it doesn't matter if you rebind the closure or not. Of course, > with rebinding you can easily shoot yourself in the foot by calling > non-existing method - but so you can with $foo->$bar() or $foo() or a number > of other ways. So I think if this construct is expressed in a way that makes > the intent clear (i.e., no implicit rebinding) then it would be OK. > -- > Stanislav Malyshev, Zend Software Architect > stas@zend.com   http://www.zend.com/ > (408)253-8829   MSN: stas@zend.com > -- Regards, Victor

« previous php.internals (#46121) next »