Created
December 25, 2016 11:55
-
-
Save gorkamu/90f84a044b1c777683994ad734e906fb to your computer and use it in GitHub Desktop.
Ejemplo de métodos __call() y __callStatic()
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 | |
class MethodTest | |
{ | |
public function __call($name, $arguments) | |
{ | |
// Nota: el valor $name es sensible a mayúsculas. | |
echo "Llamando al método de objeto '$name' " | |
. implode(', ', $arguments). "\n"; | |
} | |
/** Desde PHP 5.3.0 */ | |
public static function __callStatic($name, $arguments) | |
{ | |
// Nota: el valor $name es sensible a mayúsculas. | |
echo "Llamando al método estático '$name' " | |
. implode(', ', $arguments). "\n"; | |
} | |
} | |
$obj = new MethodTest; | |
$obj->runTest('en contexto de objeto'); | |
MethodTest::runTest('en contexto estático'); // Desde PHP 5.3.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment