I’ve read about this interesting syntax in PHP:
$value = (new MyClass)->attribute1;
- Is it ok to use it? I’ve never seen anything like this in any code I’ve analyzed. Any pros and cons?
-
Why can’t I set the attribute using this syntax? Structures like this:
(new MyClass)->attribute1 = ‘value1’;
throw errors at ‘=’ sign, no matter if the attribute exists in the class already.
Well i don’t see the point of using it since you loose your reference to the object, you cannot use it anymore, and it breaks the OO concept.
I think (new MyClass)->attribute1 is resolved first, so it is the same as writing something like 42 = 12