Skip to content

Instantly share code, notes, and snippets.

@yyong37
Created February 16, 2019 12:26
Show Gist options
  • Save yyong37/2a4b3831a709cbcbc6fd6cd17395a731 to your computer and use it in GitHub Desktop.
Save yyong37/2a4b3831a709cbcbc6fd6cd17395a731 to your computer and use it in GitHub Desktop.
<?php
// we can use this, make our code simple and short.
class MethodTest
{
public function __call($name, $arguments)
{
// Note: value of $name is case sensitive.
echo "Calling object method '$name' "
. implode(', ', $arguments). "\n";
}
/** As of PHP 5.3.0 */
public static function __callStatic($name, $arguments)
{
// Note: value of $name is case sensitive.
echo "Calling static method '$name' "
. implode(', ', $arguments). "\n";
}
}
$obj = new MethodTest;
$obj->runTest('in object context');
MethodTest::runTest('in static context'); // As of PHP 5.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment