Namespace Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lastkarrde
Forum Newbie
Posts: 3
Joined: Mon Jun 01, 2009 6:40 pm

Namespace Problem

Post by lastkarrde »

I'm having problem with a section of code with a variable namespace.

This code works fine:

Code: Select all

 
$c = new \Apps\Admin\Views\Index;
 
However this code does not:

Code: Select all

 
 
echo $val[1];
// Outputs \Apps\Admin\Views\Index;
 
$c = new $val[1]
 
//( ! ) Fatal error: spl_autoload() [function.spl-autoload]: Class \Apps\Admin\Views\Index could not be loaded in C:\wamp\www\_dev\Rain\Urls\Router.php on line 69
 
 
My "autoloader" (PHP handles namespace autoloading automatically):

Code: Select all

 
spl_autoload_extensions(".php");
spl_autoload_register();
 
I've trawled through the manual with no luck.. :(

Any ideas?
rajeevbharti
Forum Newbie
Posts: 12
Joined: Fri Oct 30, 2009 12:43 am
Location: Delhi

Re: Namespace Problem

Post by rajeevbharti »

lastkarrde wrote:I'm having problem with a section of code with a variable namespace.

This code works fine:

Code: Select all

 
$c = new \Apps\Admin\Views\Index;
 
However this code does not:

Code: Select all

 
 
echo $val[1];
// Outputs \Apps\Admin\Views\Index;
 
$c = new $val[1]
 
//( ! ) Fatal error: spl_autoload() [function.spl-autoload]: Class \Apps\Admin\Views\Index could not be loaded in C:\wamp\www\_dev\Rain\Urls\Router.php on line 69
 
 
My "autoloader" (PHP handles namespace autoloading automatically):

Code: Select all

 
spl_autoload_extensions(".php");
spl_autoload_register();
 
I've trawled through the manual with no luck.. :(

Any ideas?

can u explain what do you want and when this problem is occur. are u using oops concept of php.
lastkarrde
Forum Newbie
Posts: 3
Joined: Mon Jun 01, 2009 6:40 pm

Re: Namespace Problem

Post by lastkarrde »

Index is a class located in /Apps/Admin/Views/Index.php . I want to instantiate it.
Post Reply