php - Autoload namespaces based on directory structure -


according top comment on php page spl_autoload_register( ) :

good news php 5.3 users namespaced classes:

when create subfolder structure matching namespaces of >containing classes, never have define autoloader.

<?php     spl_autoload_extensions(".php"); // comma-separated list     spl_autoload_register(); ?> 

however, when have following structure:

* classes/someclass.php

* index.php

where someclass.php contains following:

<?php     class someclass {         function __construct( ) {             echo 'it works!';         }     } ?> 

and index.php contains:

<?php     spl_autoload_extensions(".php");     spl_autoload_register();      new classes\someclass; ?> 

then following error:

fatal error: spl_autoload(): class classes\someclass not loaded

am getting wrong? how can make work?

from comments

this doesn't work either class:

<?php     namespace classes;     class someclass {         function __construct( ) {             echo 'it works!';         }     } ?> 

in someclass.php file must define namespace @ begginning.

<?php  namespace classes; 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -