Search code examples
phpclassnamespacesiteratorspl

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 :)


Solution

  • 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.