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.

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