Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:77753 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81248 invoked from network); 3 Oct 2014 00:13:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Oct 2014 00:13:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=codekestrel@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=codekestrel@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.220.196 as permitted sender) X-PHP-List-Original-Sender: codekestrel@googlemail.com X-Host-Fingerprint: 209.85.220.196 mail-vc0-f196.google.com Received: from [209.85.220.196] ([209.85.220.196:64319] helo=mail-vc0-f196.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 87/08-33841-93AED245 for ; Thu, 02 Oct 2014 20:13:45 -0400 Received: by mail-vc0-f196.google.com with SMTP id ij19so35916vcb.3 for ; Thu, 02 Oct 2014 17:13:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=uqar/9F3RJzzBFTpbzO+ewJjRkMgR5Bd5pWL2UXID5s=; b=AnHpzSs6c2sVzeejCCvjV6Zw2ViNgzDYfIHzioG4wuENqlFgH3IZ+/P06nY8Ns10yw fC5lI6iKQh9DZXRjsF6wPkgW3sCb4Fcvy2qlSUT0lu9VqMl0VQxQ5qhKpEXZcwe0625I 88N3o4TGsMihzVqaZpj+9UNQZd8C9Ky7SIOoIF2Lccmtwlj6xNps+8uWiHz2NWfKgntM RLq+lyA0oXhrY+S+3duj5V/88dfV9pqkj/eCJxKb8wRjnRv1tSn3wTSFUDDfDYUdJF6c fZ5rtxANjvycFdUNUWsQITPSzTCKEWnooldKHnISAi3aGMMHcpsOV/JA5ulGoZNxNVB/ D61g== MIME-Version: 1.0 X-Received: by 10.52.111.232 with SMTP id il8mr1274997vdb.22.1412295221723; Thu, 02 Oct 2014 17:13:41 -0700 (PDT) Received: by 10.52.162.35 with HTTP; Thu, 2 Oct 2014 17:13:41 -0700 (PDT) In-Reply-To: <78BE550F-8867-4DCD-99E1-B2EFF114AE3A@ajf.me> References: <78BE550F-8867-4DCD-99E1-B2EFF114AE3A@ajf.me> Date: Fri, 3 Oct 2014 01:13:41 +0100 Message-ID: To: Andrea Faulds Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=bcaec54860d4024a640504799b7d Subject: Re: [PHP-DEV] Concept: Custom Type Hinting From: codekestrel@googlemail.com (Dominic Grostate) --bcaec54860d4024a640504799b7d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 3 October 2014 00:49, Andrea Faulds wrote: > Functions in PHP cannot be autoloaded, so this would be quite inconvenien= t > to use. Will people bother adding an include to every file merely to use > typehints? Or are typehints classes, in which case, why not simply define > them as a class rather than adding a new keyword? Or are they are new kin= d > of autoloaded thing? > > As Johannes mentioned, this would require a function call every time an > argument is passed. Unlike, say, auto boxing, once validated, you will > still need to validate it again for each call. The performance impact isn= =E2=80=99t > so good. > > How does this handle references, and how does it handle null? How is > inheritance/interface compatibility dealt with? > They would be treated with the same respect as classes, in the same sense as traits are. Therefore the autoloading would apply to them, as would namespaces. Using actually classes was my first though. I was thinking about a special interface like "TypeHint" which would invoke special treatment when used in type hinting. However I was getting caught up in the semantics of what contract the class should have with the interface. Regarding the additional function calls, I don't know. If the performance hit is due to calling the user defined handler, then I would justify it by arguing that a similar hit would be suffered from the necessity to use a strict type to begin with, when the user validates the values in the method which requires it. If however you are referring to an engine function call made to determine if the type hint is indeed a special type hint or a class, then yes I would agree. For references I proposed that the value parsed to the handler would be a reference of the actual argument, so any changes made in the handler would propagate to the previous scope if the original argument is intended to *be* a reference. For inheritance and compatibility, I hadn't thought about, but considering a sub class or implementer cannot break the compatibility of its parent/interface, the same rules would apply. Thanks, Dominic --bcaec54860d4024a640504799b7d--