<?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']);
- Output for 5.6.8 - 5.6.16, 7.0.0 - 7.0.1
- Fatal error: Cannot redeclare _() in /in/tMujt on line 11
Process exited with code 255. - Output for 5.5.24 - 5.5.30
- Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/tMujt on line 2
Process exited with code 255.
preferences:
167.95 ms | 1386 KiB | 25 Q