|
|
|
|
|
by NaN1352
1670 days ago
|
|
Genuine question from a php hobbyist : what is the equivalent of Typescript’s ability to declare an object’s structure? It’s really weird to me, I mean don’t we do this all the time? Work with eg. an $options array/obj passedto a constructor, or say, a message decoded from JSON… I could write $name = $message[‘username’] … and there is no checks in ide or runtime, while the phpdoc will just document $message to be an object or array… what am I missing? It looks like php devs create full blown classes to represent just about every data strcuture, but what if it’s just data and you don’t need any attached logic’ Isn’t there a concise way to declare a complex type? |
|
Typed properties, constructor properties, and Read-only properties can significantly reduce the code bloat.
- https://php.watch/versions/8.0/constructor-property-promotio...
- https://php.watch/versions/8.1/readonly