Re: A modest proposal: __contructStatic
| From: | Rowan Collins | Date: | Sun, 15 Feb 2015 23:04:47 +0000 |
| Subject: | Re: A modest proposal: __contructStatic | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-82763@lists.php.net to get a copy of this message | ||
On 15/02/2015 19:04, Patrick Schaaf wrote:
By neccessity the implementation of this class set, must make use of both __call() and __callStatic() magic methods, with both then dispatching to a delegate phpredis instance, and in the case of __callStatic(), making up-front a singleton like "new self" once. For a set of additional helper methods (not present on the underlying phpredis) I additionally have a special mapping array of real method names to internal implementation names.A quick thought - if you want to stick with the "magic static call" pattern, you can implement this much more simply by doing something similar to Laravel's "facades" [1]: class MyRedis extends Redis { // extra instance methods here } class MyRedisFacade { private static $instance; public static function __callStatic($method, $params) { if ( is_null(self::$instance) ) { self::$instance = new MyRedis; } self::$instance->$method(...$params); } } This basically implements in userspace what you propose to add to the language, with the only caveat being that you must separate the concerns of adding extra functionality, and wrapping it in a static facade, into two separate classes. [1] http://laravel.com/docs/4.2/facades -- Rowan Collins [IMSoP]