Hi, Laruence:

   I mean pass a wrong class object to a function/method. if the type
hinted Class didn't loaded, we
could try to load it. (if it's the right class, nothing happened), eg.

         function func(NotFoundClass $a) {}

maybe we could pass another class instance.
$a = new DemoClass();
func($a);

It would be useful for class_alias like Bug#61422 requested.
It's a little narrow feature usage scenario,but it gives a way to handle
it. so I think
It might be useful。
 if failed to autoload it raise E_CATCHABLE_FATAL, loaded class will simple
released
 if user catch the E_CATABLE_FATAL, loaded class will be useful, since it
will be used later.
 if loaded success everyone is happy.


On 1 May 2012 20:25, Laruence <larue...@php.net> wrote:

> On Tue, May 1, 2012 at 8:03 PM, reeze <reeze....@gmail.com> wrote:
> > Hi internals:
> > danko reported this bug#61422: Lack of autoload on type hinting breaks
> > class_alias。
> > now parmeter type hint DID NOT trying to autoload.  I think allow it
> > autoloading could be helpful.
> >
> > BUGS&Commit for quick refer:
> > - https://bugs.php.net/bug.php?id=61422
> > - https://bugs.php.net/bug.php?id=39003
> > - http://svn.php.net/viewvc?view=revision&revision=220906
> >
> > PROPOSAL(FR):
> > **I'm asking if we can enable type hint autoloading?**
> >
> > I did some homework:
> > - Before FIX for #39003, parameter type hint will try to autoload the
> hint
> > class if not found.
> >           after this fix it will not. in bug#39003: the final result was
> DOC
> > Problem, seems we all agreed
> >           that it SHOULD autoloading.
> > - But in
> > revision: http://svn.php.net/viewvc?view=revision&revision=220906 It was
> > **FIXED**
> >           I try to search RFC about typehint, I didn't find anything
> about
> > it. It was commited really long time ago
> >           almost 6 years ago, it would be very nice if Antony
> Dovgal still
> > remember it;)
> >
> > REASON:
> >     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,
> >     I mean it wouldn't hurt performance.
> > 2. Class will be used for sure, so trying to autoload it is reasonable:
> >        - If we need check certain Class, then we have to use the class in
> > function/method.
> >        - most of time it already loaded*, so autoloading happened rarely.
> > 3. If pass the wrong type and the hinted class not found  this gives
> > autoloader a change to handle it
> >     like the #61422's test script did. we can do something if not found.
> > since we use the class in
> >     function/method, autoload the class is reasonable. most of the time
> we
> > would not use the *FEATURE*,
> >     but it could make it more flexible.
> >
> > PATCH:
> >
> > 1. change zend_verify_arg_class_kind to autoload class
> > 2. if class can't load, zend_fetch_class silently return (No fatal here)
> to
> > give zend_verify_arg_class_kind a chance
> >     to report previous catchable_fatal_error eg:
> > Catchable fatal error: Argument 1 passed to func() must be an instance of
> > AX, integer given。
> >
> > 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
>
>
>
> --
> Laruence  Xinchen Hui
> http://www.laruence.com/
>



-- 
http://reeze.cn

Reply via email to