Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal Error RecursiveIteratorIterator not found

As the title says, when I instantiate a class I get this message :

Fatal error: Class 'Envato\RecursiveIteratorIterator' not found in C:\Users\rgr\Apache\htdocs\Roland Groza [ 3.0 ]\class\envato\envato.php on line 359

You can view the class here : Class ;

I'm instantiating from another file :

require("envato.php");
$test = new Envato\EnvatoAPIWrapper();
echo "User Vitals : ".$test->get_user_vitals("chaoscod3r")."<br>";

The class is wrapped with a namespace, so that might have something to do with it, but I wasn't sure since it's been a few years since I haven't coded PHP. Hopefully someone has an idea what is it that I'm doing wrong :)

like image 335
Roland Avatar asked Feb 06 '13 12:02

Roland


2 Answers

To access non-namespaced classes like the internal classes of PHP and SPL inside of a namespace you have to use the fully qualified class name like this:

new \RecursiveIteratorIterator();

or import it explicitly at the beginning:

use \RecursiveIteratorIterator;

and then use it normally like you do.

like image 52
Fabian Schmengler Avatar answered Nov 09 '22 05:11

Fabian Schmengler


Add a use statement at the top of your namespace...

use \RecursiveIteratorIterator;

If you don't then PHP expects RecursiveIteratorIterator to exist within your current namespace, rather than in the global namespace (indicated by the leading \)

like image 33
JamesHalsall Avatar answered Nov 09 '22 04:11

JamesHalsall