ArrayAccess::offsetGet

(PHP 5 >= 5.0.0)

ArrayAccess::offsetGetOffset to retrieve

Опис

abstract public mixed ArrayAccess::offsetGet ( mixed $offset )

Returns the value at specified offset.

This method is executed when checking if offset is empty().

Параметри

offset

The offset to retrieve.

Примітки

Зауваження:

Starting with PHP 5.3.4, the prototype checks were relaxed and it's possible for implementations of this method to return by reference. This makes indirect modifications to the overloaded array dimensions of ArrayAccess objects possible.

A direct modification is one that replaces completely the value of the array dimension, as in $obj[6] = 7. An indirect modification, on the other hand, only changes part of the dimension, or attempts to assign the dimension by reference to another variable, as in $obj[6][7] = 7 or $var =& $obj[6]. Increments with ++ and decrements with -- are also implemented in a way that requires indirect modification.

While direct modification triggers a call to ArrayAccess::offsetSet(), indirect modification triggers a call to ArrayAccess::offsetGet(). In that case, the implementation of ArrayAccess::offsetGet() must be able to return by reference, otherwise an E_NOTICE message is raised.

Значення, що повертаються

Can return all value types.

Прогляньте Також

add a note add a note

User Contributed Notes 1 note

up
0
Martin Q
4 years ago
As of PHP 7, offsetExists($offset) must return a TRUE value in order for offsetGet($offset) to be called, otherwise offsetGet($offset) will just return NULL.  This was not the case in PHP 5, so if your code suddenly stops working upon upgrade to PHP 7, make sure offsetExists() returns sensible values.
To Top