Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'DirectoryIterator' Class not found

Tags:

php

symfony

I'm new to simfony2, so sorry for the newbie question.

When I try to use some classes, such as DirectoryIterator or DOMDocument I receive the following exception:

PHP Fatal error:  Class 'My\TestBundle\Command\DirectoryIterator' not found in /var/www/simfony2/src/My/TestBundle/Command/TestCommand.php on line 214

If try to run the same code outside the simfony2 environment it code runs fine, phpinfo() shows PHP Version => 5.3.10-1ubuntu3.4 and the include path is the default plus added ZF2.

Again, I know this is probably some configuration issue as it searches the class in my bundle rather than using the build-in php class but I can't figure out how to solve this.

Edit: This is copy of the code I'm trying to execute:

protected function execute(InputInterface $input, OutputInterface $output) {
 $classes=get_declared_classes();
 print_r($classes);      
 $d= new DirectoryIterator("/");
}

When I run the command I can see the class

...
[73] => DirectoryIterator
...

But I can't use it

like image 339
SimSimY Avatar asked Dec 09 '22 18:12

SimSimY


1 Answers

This is namespace related!

Has nothing to do with symfony itself.
you should ad \ before a global class inside another namespace

$class = new \DirectoryIterator;

I suggest you read the php manual first before continuing with symfony!

like image 199
Gintro Avatar answered Dec 11 '22 09:12

Gintro