Last active
April 22, 2019 09:09
-
-
Save oxechicao/7b755660c4e899934a7f2f8d80242cd6 to your computer and use it in GitHub Desktop.
Call a method with the same signature staticly and normally.
This file contains 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 | |
class Teste | |
{ | |
public $var = 'Variável pública'; | |
public $macroFunction = ['foo' => 'fooFunction']; | |
public $staticMacro = ['foo' => 'fooStatic']; | |
public function fooFunction() | |
{ | |
echo $this->var; | |
} | |
public static function fooStatic() | |
{ | |
return (new static)->fooFunction(); | |
} | |
public static function __callStatic($name, $arguments) | |
{ | |
echo 'static' . "\n"; | |
return call_user_func(array('Teste', (new static)->staticMacro[$name])); | |
} | |
public function __call($name, $arguments) | |
{ | |
echo 'normal' . "\n"; | |
return call_user_func(array($this, $this->macroFunction[$name]), $arguments); | |
} | |
} | |
Teste::foo(); | |
(new Teste)->foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment