- var_dump: documentation ( source)
- strtolower: documentation ( source)
<?php
class JsonSerializer
{
public static function serialize($value)
{
var_dump($value);
}
public function __call($method, $args)
{
if ('serialize' !== strtolower($method)) {
throw new \BadMethodCallException('Call to undefined method '.__CLASS__."::$method");
}
return self::serialize(...$args);
}
}
JsonSerializer::serialize('foo');
(new JsonSerializer())->serialize('bar');
try {
(new JsonSerializer())->baz('qux');
} catch (\Exception $e) {
var_dump($e->getMessage());
}