/**
* @property MyClass $self_ref Reference to myself
* @method string greet(string $who) Hello that guy
*/
class MyClass
{
/**
* @param string $name Name of pseudo-property do invoke
* @returns MyClass|null Reference to instance or null if
* no name provided.
*/
public function __get(string $name): ?MyClass
{
if( $name === 'self_ref' )
return $this;
return null;
}
/**
* @param string $name Name of implicit function to call.
* @param array $args Array of arguments passed to call.
* @returns string The greeting string or null if no name.
*/
public function __call(string $name, array $args): string
{
if( $name === 'greet' )
{
/** @var string $guy The name of the guy to greet */
$guy = $args[0] ?? 'everyone';
return "Hello {$guy}!";
}
return '';
}
}