SplObjectStorage::attach
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
SplObjectStorage::attach — Adds an object in the storage
警告
此函数自 PHP 8.5.0 起弃用。强烈建议不要应用此函数。
说明
#[\Deprecated(
)]
public function SplObjectStorage::attach(object
since: '8.5',message: "use method SplObjectStorage::offsetSet() instead",)]
public function SplObjectStorage::attach(object
$object, mixed $info = null): voidAdds an object inside the storage, and optionally associate it to some data.
This method is an alias of SplObjectStorage::offsetSet().
返回值
没有返回值。
更新日志
| 版本 | 说明 |
|---|---|
| 8.5.0 | This method has been deprecated in favor of SplObjectStorage::offsetSet(). |
示例
示例 #1 SplObjectStorage::attach() example
<?php
$o1 = new stdClass;
$o2 = new stdClass;
$s = new SplObjectStorage();
$s->attach($o1); // similar to $s[$o1] = NULL;
$s->attach($o2, "hello"); // similar to $s[$o2] = "hello";
var_dump($s[$o1]);
var_dump($s[$o2]);
?>以上示例的输出类似于:
NULL string(5) "hello"
参见
- SplObjectStorage::detach() - Removes an object from the storage
- SplObjectStorage::offsetSet() - Associates data to an object in the storage
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
