rfc:spl-namespace

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:spl-namespace [2008/07/21 14:54] baptiste750rfc:spl-namespace [2008/07/21 15:23] baptiste750
Line 10: Line 10:
 ==== Introduction ==== ==== Introduction ====
  
-''spl_autoload()'' is probably the first PHP instruction to make an assumption on how a logical element (a class) is bound to its source code (a file). +The present RFC suggests a new namespacing system, based on the association of a namespace to a physical path.
- +
-The default association being: Class Foo -> Foo.php +
- +
-Why not implementing a similar association between namespaces and physical paths? +
-The present RFC suggests a new namespacing system, based on that association.+
  
 ==== A new instruction: spl_namespace ==== ==== A new instruction: spl_namespace ====
Line 64: Line 59:
  
 <code php> <code php>
-spl_autoload_register(array('Foo1::Foo2::Autoloader''autoload'));+spl_namespace("Foo1::Foo2", "some/where"); 
 +(...) 
 +spl_autoload_register(array("Foo1::Foo2::Autoloader""autoload"));
 // When Foo1::Foo2::Autoloader::autoload() is called, PHP has CD to /some/where  // When Foo1::Foo2::Autoloader::autoload() is called, PHP has CD to /some/where 
 </code> </code>
 +
 +In the example above, every class succesfully autoloaded by ''Foo1::Foo2::Autoloader'' will be prefixed by ''Foo1::Foo2::'', as well as all the code inside that class.
  
 ==== Benefits ==== ==== Benefits ====
Line 91: Line 90:
 ==== Drawbacks  ==== ==== Drawbacks  ====
  
-  * ...+  * If an autoloader, for a given classname, includes a different file depending on the value of a global variable, there's no longer unicity
  
   * ...   * ...
rfc/spl-namespace.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1