array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'splobjectstorage.contains.php', 1 => 'SplObjectStorage::contains', 2 => 'Checks if the storage contains a specific object', ), 'up' => array ( 0 => 'class.splobjectstorage.php', 1 => 'SplObjectStorage', ), 'prev' => array ( 0 => 'splobjectstorage.attach.php', 1 => 'SplObjectStorage::attach', ), 'next' => array ( 0 => 'splobjectstorage.count.php', 1 => 'SplObjectStorage::count', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/spl/splobjectstorage/contains.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

SplObjectStorage::contains

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

SplObjectStorage::containsChecks if the storage contains a specific object

警告

此函数自 PHP 8.5.0 起弃用。强烈建议不要应用此函数。

说明

#[\Deprecated]
public SplObjectStorage::contains(object $object): bool

Checks if the storage contains the object provided.

参数

object

The object to look for.

返回值

Returns true if the object is in the storage, false otherwise.

示例

示例 #1 SplObjectStorage::contains() example

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

$s = new SplObjectStorage();

$s[$o1] = "hello";
var_dump($s->contains($o1));
var_dump($s->contains($o2));
?>

以上示例的输出类似于:

bool(true)
bool(false)

参见