Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71522 invoked from network); 1 May 2012 13:17:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 May 2012 13:17:04 -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.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:63123] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/E4-38165-E42EF9F4 for ; Tue, 01 May 2012 09:17:03 -0400 Received: by vbjk13 with SMTP id k13so3072337vbj.29 for ; Tue, 01 May 2012 06:17:00 -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=QdtDZzZ0tLCNF7vackui7bVapQMWbrDIEFsW0cs8Ne4=; b=nn63cZENs6Gwc7F0qqcauomgLbDuHESh4j9iDiGfWRThi+2BNWI6joYWXkMQXpXIau zsLY4LbSEBD9ZQhbRnp00rPuNMFVxfURGREZrQ4v2rPWR8WejZSiDRGajBpbRqjs4tpC Os6Ssh4Mml0IJNY2WCA9w77/Rfjap2pCcnYvlQrMvNjU1KgQIuuI/3JRSXbw+6DNby8M 625/HO73tAHGgh64ms+nB6oYj9yfVL7SYLSYDAr+RtL16LGLY9GGfLsVNNQkTFRcqT7s BYNbcp8XI5BkWxADPYuJRxAIdFHYT3n35/t82P7iZCS0CNHUqP5VaTwye69LkBt8CnNZ jBnw== Received: by 10.220.91.74 with SMTP id l10mr14410393vcm.41.1335878220157; Tue, 01 May 2012 06:17:00 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.180.203 with HTTP; Tue, 1 May 2012 06:16:39 -0700 (PDT) In-Reply-To: References: <3B7600EC10A34F89AA8195C7A83089C0@gmail.com> Date: Tue, 1 May 2012 21:16:39 +0800 X-Google-Sender-Auth: RZz3tp9nRsLrFHpjkbcRpdim_aI 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 9:07 PM, reeze wrote: > Hi, Laruence: > > =C2=A0 =C2=A0I mean pass a wrong class object to a function/method. if th= e type hinted > Class didn't loaded, we > could try to load it. (if it's the right class, nothing happened), eg. > > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0function func(NotFoundClass $a) {} > > maybe we could pass another class instance. > $a =3D new DemoClass(); > func($a); > > It would be useful for class_alias like Bug#61422 requested. Hi: class_alias does well with type hint now, the following script : works find now(5.3+), output : "okey" thanks > It's a little narrow feature usage scenario=EF=BC=8Cbut it gives a way to= handle it. > so I think > It might be useful=E3=80=82 > =C2=A0if failed to autoload it raise E_CATCHABLE_FATAL, loaded class will= simple > released > =C2=A0if user catch the E_CATABLE_FATAL, loaded class will be useful, sin= ce it > will be used later. > =C2=A0if loaded success everyone is happy. > > > On 1 May 2012 20:25, Laruence wrote: >> >> 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 hint= ing breaks >> > class_alias=E3=80=82 >> > now parmeter=C2=A0type hint DID NOT trying to autoload. =C2=A0I think = allow 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= the >> > hint >> > class if not found. >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 after this fix it will not. in bug#= 39003: 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=3D22= 0906=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 ver= y nice 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 a= ny >> > 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 h= ave to use the class >> > in >> > function/method. >> > =C2=A0 =C2=A0 =C2=A0 =C2=A0- most of time it already loaded*, so autol= oading happened >> > rarely. >> > 3. If pass the wrong type and the hinted class not found=C2=A0 this gi= ves >> > autoloader a change to handle it >> > =C2=A0 =C2=A0 like the #61422's test script did.=C2=A0we can do someth= ing if not found. >> > since we use the class in >> > =C2=A0 =C2=A0 function/method, autoload the class=C2=A0is reasonable. = most 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 fata= l here) >> > 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: >> =C2=A0 =C2=A0thanks for writing this, =C2=A0but I was a little confused,= =C2=A0please >> correct me if I mis-understand you. >> >> =C2=A0 =C2=A0if you pass a right instance of class to a function , how c= an that >> class not be loaded already? >> >> =C2=A0 =C2=A0for example: >> =C2=A0 =C2=A0function foo(Foo_Bar $a) { >> =C2=A0 =C2=A0} >> >> =C2=A0 =C2=A0how can you pass a Foo_Bar instance to function foo without >> Foo_Bar class already defined? >> >> >> thanks >> >> >> > >> > Thanks. >> > Best, >> > -- >> > reeze | simpie.com >> >> >> >> -- >> Laruence =C2=A0Xinchen Hui >> http://www.laruence.com/ > > > > > -- > http://reeze.cn --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/