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

SplObjectStorage::detach

PHP function Deprecated as of PHP 8.5.0 Edit on GitHub ✎

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

Removes an object from the storage

Function-8-5-0

Description

SplObjectStorage::detach(object $object): void

Removes the object from the storage.

Parameters

object

The object to remove.

Return Values

Void

Changelog

VersionDescription
8.5.0This method has been deprecated in favor of SplObjectStorage::offsetUnset.

Examples

SplObjectStorage::detach() example

php
<?php
$o = new stdClass;
$s = new SplObjectStorage();
$s->attach($o);
var_dump(count($s));
$s->detach($o);
var_dump(count($s));
?>

The above example will output something similar to:

output
int(1)
int(0)

See Also

  • SplObjectStorage::attach
  • SplObjectStorage::removeAll

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