Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62246 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96691 invoked from network); 18 Aug 2012 16:29:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2012 16:29:29 -0000 Authentication-Results: pb1.pair.com header.from=andre.romcke@ez.no; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=andre.romcke@ez.no; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ez.no designates 216.32.180.31 as permitted sender) X-PHP-List-Original-Sender: andre.romcke@ez.no X-Host-Fingerprint: 216.32.180.31 va3ehsobe005.messaging.microsoft.com Received: from [216.32.180.31] ([216.32.180.31:56804] helo=va3outboundpool.messaging.microsoft.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/79-31572-7E2CF205 for ; Sat, 18 Aug 2012 12:29:28 -0400 Received: from mail102-va3-R.bigfish.com (10.7.14.243) by VA3EHSOBE008.bigfish.com (10.7.40.28) with Microsoft SMTP Server id 14.1.225.23; Sat, 18 Aug 2012 16:29:25 +0000 Received: from mail102-va3 (localhost [127.0.0.1]) by mail102-va3-R.bigfish.com (Postfix) with ESMTP id E0886E044E; Sat, 18 Aug 2012 16:29:24 +0000 (UTC) X-Forefront-Antispam-Report: CIP:157.56.249.213;KIP:(null);UIP:(null);IPV:NLI;H:AM2PRD0710HT002.eurprd07.prod.outlook.com;RD:none;EFVD:NLI X-SpamScore: -4 X-BigFish: PS-4(zz98dI9371I1432I1418Izz1202hzzz2fh2a8h668h839hd25he5bhf0ah107ah) Received-SPF: pass (mail102-va3: domain of ez.no designates 157.56.249.213 as permitted sender) client-ip=157.56.249.213; envelope-from=andre.romcke@ez.no; helo=AM2PRD0710HT002.eurprd07.prod.outlook.com ;.outlook.com ; Received: from mail102-va3 (localhost.localdomain [127.0.0.1]) by mail102-va3 (MessageSwitch) id 1345307362486991_9667; Sat, 18 Aug 2012 16:29:22 +0000 (UTC) Received: from VA3EHSMHS011.bigfish.com (unknown [10.7.14.251]) by mail102-va3.bigfish.com (Postfix) with ESMTP id 70C26200A9; Sat, 18 Aug 2012 16:29:22 +0000 (UTC) Received: from AM2PRD0710HT002.eurprd07.prod.outlook.com (157.56.249.213) by VA3EHSMHS011.bigfish.com (10.7.99.21) with Microsoft SMTP Server (TLS) id 14.1.225.23; Sat, 18 Aug 2012 16:29:22 +0000 Received: from AM2PRD0710MB351.eurprd07.prod.outlook.com ([169.254.12.223]) by AM2PRD0710HT002.eurprd07.prod.outlook.com ([10.255.165.37]) with mapi id 14.16.0190.008; Sat, 18 Aug 2012 16:29:20 +0000 To: Nikita Popov CC: Kris Craig , Anthony Ferrara , Stan Vass , Stas Malyshev , Levi Morrison , "" Thread-Topic: [PHP-DEV] Inline typecasting / typehinting for classes and interfaces Thread-Index: AQHNefEF1xsAkzKcaEWsITcsxSxAV5dZU+IAgAAf7ICAABfkAIAA9+CxgABAbICAAGvmAIAABTkAgASUPIA= Date: Sat, 18 Aug 2012 16:29:19 +0000 Message-ID: <7EC977AE-7678-42D6-98EC-7D21D81C3689@ez.no> References: <502A86AA.2030203@sugarcrm.com> In-Reply-To: Accept-Language: nb-NO, de-DE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.255.75.4] Content-Type: text/plain; charset="iso-8859-1" Content-ID: <598BF898EF41034A91FFFB0F4021B8D7@eurprd07.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: ez.no Subject: Re: [PHP-DEV] Inline typecasting / typehinting for classes and interfaces From: andre.romcke@ez.no (=?iso-8859-1?Q?Andr=E9_R=F8mcke?=) ( resending with correct formatting, and missing context while at it, sorry= about that ) On Aug 15, 2012, at 8:33 PM, Nikita Popov wrote: > (...) >=20 > Another aspect here is that there is no reasonable syntax for this > feature, at least I can't think of one: >=20 > * The syntax `$foo =3D (InterfaceName) $container->service` is > completely out of question. It looks like a cast, but wouldn't > actually do a cast. > * Same is to be said about `InterfaceName $foo =3D > $container->service`. This syntax implies that the $foo variable will > always be of type InterfaceName, even if it is later reassigned. It's > not a sensible syntax for a one time validation > * The other three syntaxes that were mentioned were just as unclear. > E.g. `$foo =3D $container->service as InterfaceName` again looks like a > strange cast syntax and `$foo =3D $container->service is InterfaceName` > looks like the assignment should evaluate to a boolean (i.e. `is` is > some kind of `instanceof`). good points In addition, the root cause that triggered this proposal in the first place= : serve container / object registry doc issue, is kind of moot, ref bellow. >=20 > On the other hand, the current ways of accomplishing the same goal are > well-established and easy to understand: >=20 > * Using a docblock: /** @var $foo IntefaceName **/ > * Using an assertion: assert($foo instanceof InterfaceName). >=20 > I think that the assertion is a rather concise and clear way to do > this. It is much more obvious than some new and obscure `$foo =3D > (InterfaceName $container->service)` syntax. To expand on that, @Stan: If you make sure you configure your container to = injection dependencies (and in case of lazy loading, inject factories* with= type hinting in doc) instead of passing the [dependency injection] contain= er around as a registry, then you almost don't get this problem at all, and= you will avoid introducing container awareness/dependency in your architec= ture. Only place you will have this original problem though is in the code that g= ets the first dependency of the execution, like in index.php for instance, = but even then you can have Container interface for the most common root dep= endencies. In the cases that doesn't fit, you should plainly use the doc block referre= d to by Nikita, it is already supported by IDE's and won't need additional = 3 years to get support. * As alternatives to factories with or without container knowledge, there i= s one alternative that some containers support: Proxy objects: container generates proxy objects whenever you want depend= encies to be lazy loaded, they have container awareness, but this becomes 1= 00% transparent to your code, but it probably adds some overhead.=