Created
October 3, 2017 10:40
-
-
Save oskarcalvo/58573502f728a5c43eaf511ce9ae483a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| <?php | |
| namespace SwitchClass; | |
| $time_start = microtime(true); | |
| echo memory_get_usage(), "\n"; | |
| /** | |
| * Created by PhpStorm. | |
| * User: oskar | |
| * Date: 3/10/17 | |
| * Time: 10:28 | |
| */ | |
| abstract Class SwitchClass { | |
| private $data = NULL; | |
| private $method; | |
| function __construct(){} | |
| private function DefaultMethod(){} | |
| } | |
| class alternancia extends SwitchClass { | |
| private $data = NULL; | |
| private $method; | |
| function __construct($method, array $data) | |
| { | |
| $this->method = $method; | |
| $this->data = $data; | |
| if(method_exists($this, $this->method)){ | |
| $return = $this->{$method}; | |
| }else{ | |
| $return = $this->DefaultMethod(); | |
| } | |
| return $return; | |
| } | |
| private function wadus() { | |
| return $this->data; | |
| } | |
| private function wadus2() { | |
| return $this->data; | |
| } | |
| private function wadus3() { | |
| return $this->data; | |
| } | |
| private function DefaultMethod() { | |
| return $this->data; | |
| } | |
| } | |
| $method = 'wadus'; | |
| $array = ['wadus']; | |
| $clase = new alternancia($method, $array); | |
| var_dump($clase); | |
| var_dump('esto es un anónimo'); | |
| $method = 'wadus444'; | |
| $clase = new alternancia($method, $array); | |
| var_dump($clase); | |
| $time_end = microtime(true); | |
| $execution_time = ($time_end - $time_start)/60; | |
| echo '<b>Total Execution Time:</b> '.$execution_time.' Mins'; | |
| echo "\n"; | |
| echo memory_get_usage(), "\n"; |
carlescliment
commented
Oct 3, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment