Re: [RFC][DISCUSSION] Deprecation of fallback to root scope
| From: | Wes | Date: | Sat, 03 Feb 2018 10:11:08 +0000 |
| Subject: | Re: [RFC][DISCUSSION] Deprecation of fallback to root scope | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101748@lists.php.net to get a copy of this message | ||
I get that people want to do that, it's so comfortable. But is it really a
good idea? When I have that kind of problem, I use:
class Foo{
protected $date = "date";
function getDate(){
return ($this->date)();
}
}
$mockFoo = new class extends Foo{ protected $date = "my_fake_date"; };
Or dependency injection (I inject the function as closure in the ctor).
Alternatively, you could consider using https://github.com/krakjoe/uopz
which allows to redefine functions at runtime.