<?phpclassproxy{private$targets=array();publicfunction__construct(array$targets=array()){$this->targets=$targets;}publicfunction__call($method_name,$args){foreach($this->targetsas$target)if(method_exists($target,$method_name))returncall_user_func_array($target,$method_name);thrownewexception(sprintf('Method \'%s\' doesn\'t exist',$method_name));}}classfirst{publicfunctionfirst(){return'first';}}classsecond{protectedfunctionsecond(){return'second';}}$proxy=newproxy(array(newfirst,newsecond,newthird));assert('first'===$proxy->first());try{$proxy->third();assert(false);}catch(exception$e){}$proxy->second();// This trigger a fatal errorassert(false);
[^] # Re: The Hack language : PHP avec un peu de typage statique ?
Posté par LupusMic (site web personnel, Mastodon) . En réponse à la dépêche The Hack language : PHP avec un peu de typage statique. Évalué à 1.
Voici la complexité d'un proxy naïf :