Skip to content

Instantly share code, notes, and snippets.

@gorkamu
Created December 25, 2016 11:55
Show Gist options
  • Save gorkamu/90f84a044b1c777683994ad734e906fb to your computer and use it in GitHub Desktop.
Save gorkamu/90f84a044b1c777683994ad734e906fb to your computer and use it in GitHub Desktop.
Ejemplo de métodos __call() y __callStatic()
<?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