php8.5
Home/ Manual/ spl / splobjectstorage/ SplObjectStorage::valid

SplObjectStorage::valid

PHP function Edit on GitHub ✎

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Returns if the current iterator entry is valid

Description

SplObjectStorage::valid(): bool

Returns if the current iterator entry is valid.

Parameters Parameters

Return Values

Returns true if the iterator entry is valid, false otherwise.

Examples

SplObjectStorage::valid() example

php
<?php
$s = new SplObjectStorage();

$o1 = new stdClass;
$o2 = new stdClass;

$s->attach($o1, "d1");
$s->attach($o2, "d2");

$s->rewind();
while($s->valid()) {
    echo $s->key()."\n";
    $s->next();
}
?>

The above example will output something similar to:

output
0
1

See Also

  • SplObjectStorage::current
  • SplObjectStorage::getInfo

Source: reference/spl/splobjectstorage/valid.xml · from the official PHP manual (php/doc-en)