Reputation: 1617
I'm using laravel 5.6, and in my controller I have
use RecursiveIteratorIterator;
and the error I'm getting is
Class 'App\Http\Controllers\RecursiveArrayIterator' not found
So I'm being a little simplistic about it. Obviously RecursiveIteratorIterator is not a laravel function, but rather a core php function. But after reading this post https://laraveldaily.com/how-to-use-external-classes-and-php-files-in-laravel-controller/ I'm still no clearer on where to find it, or how to reference it properly.
I suppose I was expecting that all "native" php functions would just be available?
Help?
Upvotes: 1
Views: 1098
Reputation: 1852
Just to be mention, it looks like you are only importing
use \RecursiveIteratorIterator;
and also calling RecursiveArrayIterator
somewhere in the code. try importing both.
use \RecursiveIteratorIterator;
use \RecursiveArrayIterator;
Upvotes: 1
Reputation: 22911
You want to put a backslash in front (No need to put use ...
at the top), to specify a root/global class:
\RecursiveIteratorIterator;
For more information, refer to the PHP documentation here:
Example #3 Accessing internal classes in namespaces
<?php
namespace foo;
$a = new \stdClass;
function test(\ArrayObject $typehintexample = null) {}
$a = \DirectoryIterator::CURRENT_AS_FILEINFO;
// extending an internal or global class
class MyException extends \Exception {}
?>
Upvotes: 3