URL::getIterator()

The external iterator receiver.

URL::getIterator(): Traversable;

This method is a requirement to be able to implement the IteratorAggregate interface and aims to make the object iterable directly. You won’t use this method directly, iteration control structures such as for, foreach and while will call this method automatically.

Example

$url = new URL('http://127.0.0.1/foo/bar/baz?foo=bar#baz');

// Using `for` loop
for ($i = 0, $j = count($url); $i < $j; ++$i) {
    echo $i . ': ' . $url[$i] . '<br>';
}

// Using `foreach` loop
foreach ($url as $k => $v) {
    echo $k . ': ' . $v . '<br>';
}

// Using `while` loop
$iterator = $url->getIterator();
while ($iterator->valid()) {
    echo $iterator->key() . ': ' . $iterator->current() . '<br>';
    $iterator->next();
}

URL::current()

Returns the full URL address along with its query and hash.

URL::getIterator()

The external iterator receiver.