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

SplObjectStorage::setInfo

PHP function Edit on GitHub ✎

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

Sets the data associated with the current iterator entry

Description

SplObjectStorage::setInfo(mixed $info): void

Associates data, or info, with the object currently pointed to by the iterator.

Parameters

info

The data to associate with the current iterator entry.

Return Values

Void

Examples

SplObjectStorage::setInfo() 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()) {
    $s->setInfo("new");
    $s->next();
}
var_dump($s[$o1]);
var_dump($s[$o2]);
?>

The above example will output something similar to:

output
string(3) "new"
string(3) "new"

See Also

  • SplObjectStorage::current
  • SplObjectStorage::rewind
  • SplObjectStorage::key
  • SplObjectStorage::next
  • SplObjectStorage::valid
  • SplObjectStorage::getInfo

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