@ 2020-04-14T14:14:11Z <?php declare(strict_types=1);
class Foo
{
private array $data = [];
public function __set(string $name, $value): void
{
$this->data[$name] = $value;
}
public function __isset(string $name): bool
{
return isset($this->data[$name]);
}
public function __unset(string $name): void
{
unset($this->data[$name]);
}
}
$foo = new Foo();
$one = 1;
$two = 2;
$foo->$one = 'one';
$foo->$two = 'two';
var_dump(
isset($foo->$one), // true
isset($foo->$two) // true
);
unset($foo->$one);
var_dump(
isset($foo->$one) // false
);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.25 , 8.4.1 - 8.4.12 bool(true)
bool(true)
bool(false)
Output for 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in /in/HhPZP on line 5
Process exited with code 255 . preferences:dark mode live preview ace vim emacs key bindings
85.14 ms | 407 KiB | 5 Q