Monday, 15 September 2014

How do I use PHP namespaces with autoload? -


When I try to use autoload and namespaces, I get this error:

Fatal Error: 'class' on line 10 /usr/local/www/apache22/data/public/php5.3/test .php >

Does anyone tell me what I am doing?

This is my code:

Class1.php:

   

test.php:

  & lt ;? Php function __autoload ($ class) {$ class requires '.php'; } Use the person \ Barnes \ David; $ Square = new square 1 (); ? & Gt;  

Class 1 is not within the global scope.

See below for a working example:

  & lt ;? Php function __autoload ($ class) {$ parts = explode ('\\', $ class); End ($ parts) is required '.php'; } Use the person \ Barnes \ David as MyPerson; $ Square = new MyPerson \ Class1 ();  

Edit (2009-12-14):

To just clarify, use "as ..." My use of the example was simple.

The option was:

  $ class = new person \ barns \ David \ class 1 ();  

or

  Use Person \ Barnes \ David \ Class1; // ... $ class = new square 1 ();  

No comments:

Post a Comment