Christian Seiler wrote:
> Hi Greg,
>
>   
>> (I meant commit when I said patch, sorry :)
>>
>> http://news.php.net/php.cvs/58696
>> and
>> http://news.php.net/php.cvs/58697
>>     
>
> Thanks, looks fine to me. However, I noticed that closures don't work
> with spl_autoload_unregister() and spl_autoload_functions(). Also,
> classes that define __invoke work with spl_autoload_functions() but not
> with spl_autoload_unregister() - unless array ($o, '__invoke') is given
> to spl_autoload_register() directly, then the same will work for unregister.
>   
Hi,

I first replied off-list accidentally.  I wonder if the problem is that
spl_autoload_register should not just be checking to see if zcallable is
IS_OBJECT, but also if it is an instance of Closure.  That should clear
up the examples below (spl_autoload_register($blah) where $blah is not a
closure should not work).  spl_autoload_unregister probably just needs a
cut/paste of the code I committed to spl_autoload_register for munging a
closure name with the addition of Closure instanceof check.

Also, those examples would make great .phpt tests :).

Greg
> Or, to sum it up:
>
> i) Real Closures
>
> $c = function ($class) { var_dump ('foo'); }
> spl_autoload_register ($c);
>
> var_dump (spl_autoload_functions ()); // '{closure}'
>
> spl_autoload_unregister ($c); // no effect
>
> ii) Invokables
>
> WORKS:
>
> <?php
>
> class Autoloader {
>   private $dir;
>   public function __construct ($dir) {
>     $this->dir = $dir;
>   }
>   public function __invoke ($class) {
>     var_dump ("{$this->dir}/$class.php");
>   }
> }
>
> $al1 = new Autoloader ('d1');
> $al2 = new Autoloader ('d2');
>
> spl_autoload_register (array ($al1, '__invoke'));
> spl_autoload_register (array ($al2, '__invoke'));
>
> var_dump (spl_autoload_functions ());
>
> spl_autoload_unregister (array ($al1, '__invoke'));
>
> $x = new Test;
>
> ?>
>
> SEMI-WORKS:
>
> <?php
>
> class Autoloader {
>   private $dir;
>   public function __construct ($dir) {
>     $this->dir = $dir;
>   }
>   public function __invoke ($class) {
>     var_dump ("{$this->dir}/$class.php");
>   }
> }
>
> $al1 = new Autoloader ('d1');
> $al2 = new Autoloader ('d2');
>
> spl_autoload_register ($al1);
> spl_autoload_register ($al2);
>
> var_dump (spl_autoload_functions ());
>    // gives array ($object, '__invoke') instead of
>    // directly $object - but that's at least equivalent
>
> spl_autoload_unregister ($al1);
>    // no effect
> spl_autoload_unregister (array ($al1, '__invoke'));
>    // no effect
>
> $x = new Test;
>
> ?>
>
> Regards,
> Christian
>   


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to