> De : Ryan Pallas [mailto:derokor...@gmail.com] > > With all the new typing and strict mode in PHP7, I'm wondering if there is > any planned support for typing of properties in a future version. IE > something like: > > class Foo {} > class Bar { > public Foo $foo; > > public function __construct(Foo $foo) { > $this->foo = $foo; > } > } > > This seems really useful to me. If its not something that was considered > before I can try to write up an RFC for this, however I'm not sure if this > was already considered and denied. Any feedback would be greatly > appreciated.
Hi, I proposed this as an addition to scalar type hinting when we were discussing the STH RFC some months ago. Zeev and Dmitry, like Rasmus today, thought it was probably not possible to implement it without huge changes to the engine. After thinking more about it, I think they're absolutely right. What you want to implement is not an additional compile-time check, it's attaching type hints to object properties. That's a runtime check *and* a possible conversion *each* time a property is assigned. The problem is that the current engine makes it impossible to trap every zval assignments, let alone the question of performance. If you look at parameter type hints, argument types are checked only once, when they are received by the function. Then, in the function body, you can assign any value/type to every received argument, that's impossible to check. Rewriting your example to show the feature has nothing to do with compile-time checks : public function __construct(Foo $foo) { manage($foo); $this->foo=$foo; /* Compile-time OK, Runtime error */ } /* In another file, somewhere... */ public function manage(&$obj) { ... $obj='bar'; } Regards François -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php