SplObjectStorage::offsetSet

(PHP 5 >= 5.3.0, PHP 7)
Associates data to an object in the storage
public void SplObjectStorage::offsetSet ( object $object [, mixed $data = NULL ] )

Associate data to an object in the storage.

Note:

SplObjectStorage::offsetSet() is an alias of SplObjectStorage::attach().

Parameters:
object

The object to associate data with.

data

The data to associate with the object.

Returns:

No value is returned.

Examples:
SplObjectStorage::offsetSet() example
<?php
$s = new SplObjectStorage;

$o1 = new StdClass;

$s->offsetSet($o1, "hello"); // Similar to $s[$o1] = "hello";

var_dump($s[$o1]);
?>

The above example will output something similar to:

string(5) "hello"
See also:

SplObjectStorage::attach() -

SplObjectStorage::offsetGet() -

SplObjectStorage::offsetExists() -

SplObjectStorage::offsetUnset() -

doc_php
2016-02-24 16:19:35
Comments
Leave a Comment

Please login to continue.