Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60386 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66709 invoked from network); 1 May 2012 12:25:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 May 2012 12:25:27 -0000 Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:52619] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 26/24-38165-436DF9F4 for ; Tue, 01 May 2012 08:25:24 -0400 Received: by vcbfo14 with SMTP id fo14so3063083vcb.29 for ; Tue, 01 May 2012 05:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=mcCMXMuapN+KFAGbcROHWPbPLYiaiAJ+fvOplgUwWn0=; b=pR0x/MC/h3BwIFZcLWbkVuwq68vMFw60jD0gsUFxzwPQBq7/Id0ffv7rwzRU2o1GEr cqPpVnQuMslzdVgk/kKziIq2/WAacn4tvF2GaKnUkjesuALhuOYrbtlBOWoi/0TXegTU a7dsv3F0aahsasdZo1XIni3TmyolHJcXBShw9m3soo6Qs5GDxWiE9jYKzHf85YjpRe84 HYLwtSFqs10ClAa8s4Y7UXHuCVengW2aI4L2SyHXLqTq5lo9qCF58YNOK58FfvHorK8e LPg7MkkpBWnc2yp5VfRQK5xUNogQyofRXYD2tbP7+DN7b5dyVuutn+YrxKgdaI7XGqWG Hdlg== Received: by 10.220.210.20 with SMTP id gi20mr24591046vcb.42.1335875121945; Tue, 01 May 2012 05:25:21 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.180.203 with HTTP; Tue, 1 May 2012 05:25:01 -0700 (PDT) In-Reply-To: <3B7600EC10A34F89AA8195C7A83089C0@gmail.com> References: <3B7600EC10A34F89AA8195C7A83089C0@gmail.com> Date: Tue, 1 May 2012 20:25:01 +0800 X-Google-Sender-Auth: ztHOfdkPJ8hOVswVzF1_vtQLMgA Message-ID: To: reeze Cc: "internals@lists.php.net" , tony2001@php.net, danko@very.lv, stas@php.net, dmitry@php.net, nikic@php.net, felipe@php.net Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: Bug/Req:#61422顛 enble Type Hint autoloading From: laruence@php.net (Laruence) On Tue, May 1, 2012 at 8:03 PM, reeze wrote: > Hi internals: > danko=C2=A0reported this bug#61422:=C2=A0Lack of autoload on type hinting= breaks > class_alias=E3=80=82 > now parmeter=C2=A0type hint DID NOT trying to autoload. =C2=A0I think all= ow it > autoloading could be helpful. > > BUGS&Commit for quick refer: > -=C2=A0https://bugs.php.net/bug.php?id=3D61422 > -=C2=A0https://bugs.php.net/bug.php?id=3D39003 > -=C2=A0http://svn.php.net/viewvc?view=3Drevision&revision=3D220906 > > PROPOSAL(FR)=EF=BC=9A > **I'm asking if we can enable type hint autoloading?** > > I did some homework: > -=C2=A0Before FIX for #39003, parameter type hint will try to autoload th= e hint > class if not found. > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 after this fix it will not. in bug#390= 03: the final result was DOC > Problem, seems we all agreed > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 that it SHOULD autoloading. > - But in > revision:=C2=A0http://svn.php.net/viewvc?view=3Drevision&revision=3D22090= 6=C2=A0It was > **FIXED** > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 I try to search RFC about typehint, I = didn't find anything about > it. It was commited really long time ago > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 almost 6 years ago, it would be very n= ice if=C2=A0Antony Dovgal=C2=A0still > remember it;) > > REASON=EF=BC=9A > =C2=A0 =C2=A0 Here is my reason to ask whether we can enable it: > > 1. Autoload will only happened when function/method calling. so does any > other autoloading, > =C2=A0 =C2=A0 I mean it wouldn't hurt performance. > 2. Class will be used for sure, so trying to autoload it is reasonable: > =C2=A0 =C2=A0 =C2=A0 =C2=A0- If we need check certain Class, then we have= to use the class in > function/method. > =C2=A0 =C2=A0 =C2=A0 =C2=A0- most of time it already loaded*, so autoload= ing happened rarely. > 3. If pass the wrong type and the hinted class not found=C2=A0 this gives > autoloader a change to handle it > =C2=A0 =C2=A0 like the #61422's test script did.=C2=A0we can do something= if not found. > since we use the class in > =C2=A0 =C2=A0 function/method, autoload the class=C2=A0is reasonable. mos= t of the time we > would not use the *FEATURE*, > =C2=A0 =C2=A0 but it could make it more flexible. > > PATCH: > > 1. change=C2=A0zend_verify_arg_class_kind to autoload class > 2. if class can't load, zend_fetch_class=C2=A0silently return (No fatal h= ere) to > give=C2=A0zend_verify_arg_class_kind a chance > =C2=A0 =C2=A0 to report previous catchable_fatal_error eg=EF=BC=9A > Catchable fatal error: Argument 1 passed to func() must be an instance of > AX, integer given=E3=80=82 > > a simple patch attached request for comment. > > Finally, What do you guys think about it? Hi: thanks for writing this, but I was a little confused, please correct me if I mis-understand you. if you pass a right instance of class to a function , how can that class not be loaded already? for example: function foo(Foo_Bar $a) { } how can you pass a Foo_Bar instance to function foo without Foo_Bar class already defined? thanks > > Thanks. > Best, > -- > reeze | simpie.com --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/