XF 2.2 "RecursiveIteratorIterator" Not Found

Digital Jedi

Well-known member
Does xF just not like RecursiveIteratorIterator? This code worked on a non xF test page. Is it a nesting issue?

1680191004002.webp

PHP:
<?php
namespace ycard;

class ycard{
    public static function getYcard(\XF\Pub\Controller\AbstractController $controller, \XF\Mvc\Reply\AbstractReply &$reply) {
$url = 'https://db.ygoprodeck.com/api/v7/cardinfo.php';
$parameter = $_SERVER['QUERY_STRING'];
$request_url = $url . '?' . $parameter;

$curl = curl_init($request_url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);


$response = curl_exec($curl);
curl_close($curl);

//echo $response . PHP_EOL;

$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($response, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
    if(!is_array($val)) {
        if($key == "set_code") {
            print "<br/>";
        }
    print $key."    : ".$val . "<br/>";
    }


            }
        }
?>
 
Since your class exists inside a namespace, you would need to use the global namespace prefix (eg. \RecursiveIteratorIterator(...) etc) or import them (use RecursiveIteratorIterator;) after your namespace declaration.
 
Since your class exists inside a namespace, you would need to use the global namespace prefix (eg. \RecursiveIteratorIterator(...) etc) or import them (use RecursiveIteratorIterator;) after your namespace declaration.
Ah, I tried using the global namespace prefix, but not importing. That one works. Not sure why the prefix didn't. Thanks for that.

PHP:
namespace ycard;
use RecursiveIteratorIterator;
use RecursiveArrayIterator;
 
Last edited:
Back
Top Bottom