Aleksandar Zivanovic - 2019-12-11 14:54:51 - In reply to message 1 from Chi Hoang
First- Yes this is PHP 7.1+ compatible code.
Now to answer on other questions.
1. function getFullName(): string <- : string? -> It tells PHP runtime that it expect this method to return string.
2. function decorate(object $object, string $attributeName, $value, ?string $class = null): object <- ?string $class = null and also ):object? -> Typed arguments, it expect $class to be either NULL or string, and expect method to return an object (object is universal type)
3. function (...$arguments) use ($closure, $context) <- What means ...$arguments and use ...? -> ...$arguments will hold all provided parameters (arguments) in this one array.
keyword "use" is used to give access to certain variables inside function scope, in this case those variables are $closure and $context
4. if (is_callable($this->__methods[$name] ?? null)) <- What means ?? null ? ->
In case that "$this->_methods[$name]" doesn't exist it will provide NULL.
if it were e.g $this->_methods[$name] ?? 'Hello', it would provide string 'Hello', if $this->_methods[$name] doesn't exist
Also, it is possible to undecorate an object? Say I have decorate object with 2-3 decorates but I want to remove one of it. Is it possible? - Currently, it is not, but thanks for idea.