downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SplObjectStorage::contains> <SplObjectStorage::addAll
[edit] Last updated: Fri, 25 May 2012

view this page in

SplObjectStorage::attach

(PHP 5 >= 5.1.0)

SplObjectStorage::attachオブジェクトをストレージに追加する

説明

public void SplObjectStorage::attach ( object $object [, mixed $data = NULL ] )

オブジェクトをストレージに追加し、 オプションでそれを何らかのデータに関連づけます。

パラメータ

object

追加したいオブジェクト。

data

object に関連づけるデータ。

返り値

値を返しません。

例1 SplObjectStorage::attach() の例

<?php
$o1 
= new StdClass;
$o2 = new StdClass;
$s = new SplObjectStorage();
$s->attach($o1); // $s[$o1] = NULL; と同等
$s->attach($o2"hello"); // $s[$o2] = "hello"; と同等

var_dump($s[$o1]);
var_dump($s[$o2]);

?>

上の例の出力は、 たとえば以下のようになります。

NULL
string(5) "hello"

変更履歴

バージョン 説明
5.3.0 data パラメータが追加されました。

参考



add a note add a note User Contributed Notes SplObjectStorage::attach
There are no user contributed notes for this page.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites