- is_callable: documentation ( source)
<?php
function __(array &$class, string $member, ...$args) {
if(!isset($class[$member])) exit($member.' is not a member of the class.');
else {
if(!is_callable($class[$member])) return $class[$member];
else {
if(!isset($args[0])) $class[$member]($class);
else $class[$member]($class, $args);
}
}
}
function _new(array $class, ...$args) {
$obj = $class;
if(isset($class['__construct'])) {
if(isset($args[0])) $obj['__construct']($obj, $args);
else $obj['__construct']($obj);
}
return $obj;
}
$obj = [
'foo' => '',
'bar' => function (&$this) {
$this['foo'] = ' World!';
},
'__construct' => function (&$this) {
$this['foo'] = 'Hello';
}
];
echo($obj['foo']);
__($obj, 'bar');
echo($obj['foo']);