phpday 2027 - Call for Papers

SplObjectStorage::contains

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

SplObjectStorage::contains — Checks if the storage contains a specific object

Avviso

Questa funzione è stata DEPRECATA a partire da PHP 8.5.0. Fare affidamento su questa funzione è altamente sconsigliato.

Descrizione

#[\Deprecated(
    since: '8.5',
    message: "use method SplObjectStorage::offsetExists() instead",
)]

public function SplObjectStorage::contains(object $object): bool

Checks if the storage contains the object provided.

Elenco dei parametri

object

The object to look for.

Valori restituiti

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

Log delle modifiche

Versione Descrizione
8.5.0 This method has been deprecated in favor of SplObjectStorage::offsetExists().

Esempi

Example #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));
?>

Il precedente esempio visualizzerà qualcosa di simile a:

bool(true)
bool(false)

Vedere anche:

User Contributed Notes

There are no user contributed notes for this page.
Adding new notes is disabled. Please see the links in the Found A Problem? section.
To Top