Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87160 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80114 invoked from network); 13 Jul 2015 22:56:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Jul 2015 22:56:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=francois@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=francois@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@php.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:64706] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/00-13946-E1244A55 for ; Mon, 13 Jul 2015 18:56:31 -0400 Received: from moorea (unknown [82.240.16.115]) by smtp2-g21.free.fr (Postfix) with ESMTP id 1B5A64B01B9; Tue, 14 Jul 2015 00:56:27 +0200 (CEST) Reply-To: To: "'Ryan Pallas'" , References: In-Reply-To: Date: Tue, 14 Jul 2015 00:56:10 +0200 Message-ID: <035001d0bdbf$1d0a93a0$571fbae0$@php.net> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQLKj5jnHzHAN4ZA333OTv//ogPhy5vmVXAA Content-Language: fr X-Antivirus: avast! (VPS 150713-1, 13/07/2015), Outbound message X-Antivirus-Status: Clean Subject: RE: [PHP-DEV] PHP7 and types From: francois@php.net (=?UTF-8?Q?Fran=C3=A7ois_Laupretre?=) > De : Ryan Pallas [mailto:derokorian@gmail.com] >=20 > 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: >=20 > class Foo {} > class Bar { > public Foo $foo; >=20 > public function __construct(Foo $foo) { > $this->foo =3D $foo; > } > } >=20 > 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=3D$foo; /* Compile-time OK, Runtime error */ } /* In another file, somewhere... */ public function manage(&$obj) { ... $obj=3D'bar'; } Regards Fran=C3=A7ois