I have a proposal for prototype of __autoload function in PHP 5.3.0.
In this version of PHP namespaces will be available.
Prototype of __autoload could look like this:

__autoload($classname, $namespace = null);

Now __autoload have only one argument which is a name of searched class.
Second argument could be a namespace where class is searched. It should have
default value for backward compatibility.

For example:

<?php
namespace Space1::Space2;
class A {
  public function Test() {
    $b = new B; // Class B isn't known at this moment
  }
}
?>

When user try to create new object of unknown class B __autoload function
should be called with parameter $classname = 'B' and $namespace =
'Space1::Space2'

but int this example:


<?php
namespace Space1::Space2;
class A {
  public function Test() {
    $b = new Space3::Space4::B; // Class B isn't known at this moment
  }
}
?>

Arguments should be: $classname = 'B' and $namespace = 'Space3::Space4';

I think it is the most flexible solution. It allows to create very useful
and effective  mapping mechanisms.

-- 
Wojciech Ma³ota

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

Reply via email to