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

SplObjectStorage::offsetExists

PHP function Edit on GitHub ✎

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

Checks whether an object exists in the storage

Description

SplObjectStorage::offsetExists(object $object): bool

Checks whether an object exists in the storage.

Note

SplObjectStorage::offsetExists is an alias of SplObjectStorage::contains.

Parameters

object

The object to look for.

Return Values

Returns true if the object exists in the storage, and false otherwise.

Examples

SplObjectStorage::offsetExists() example

php
<?php
$s = new SplObjectStorage;
$o1 = new stdClass;
$o2 = new stdClass;

$s->attach($o1);

var_dump($s->offsetExists($o1)); // Similar to isset($s[$o1])
var_dump($s->offsetExists($o2)); // Similar to isset($s[$o2])
?>

The above example will output something similar to:

output
bool(true)
bool(false)

See Also

  • SplObjectStorage::offsetSet
  • SplObjectStorage::offsetGet
  • SplObjectStorage::offsetUnset

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