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

search for in the

ArrayObject::offsetSet> <ArrayObject::offsetExists
[edit] Last updated: Fri, 17 May 2013

view this page in

ArrayObject::offsetGet

(PHP 5 >= 5.0.0)

ArrayObject::offsetGetDevuelve el valor en el índice especificado

Descripción

public mixed ArrayObject::offsetGet ( mixed $index )

Parámetros

index

El índice con el valor.

Valores devueltos

El valor en el índice especificado o NULL.

Ejemplos

Ejemplo #1 Ejemplo de ArrayObject::offsetGet()

<?php
$arrayobj 
= new ArrayObject(array('cero'7'ejemplo'=>'e.j.'));
var_dump($arrayobj->offsetGet(1));
var_dump($arrayobj->offsetGet('ejemplo'));
var_dump($arrayobj->offsetExists('noencontrado'));
?>

El resultado del ejemplo sería:

int(7)
string(4) "e.j."
bool(false)



add a note add a note User Contributed Notes ArrayObject::offsetGet - [2 notes]
up
3
Sam
5 years ago
If you're overloading ArrayObject, it's worth noting that while this method (when implemented by the parent) will return a reference, so code like $fakeArray['foobar']['hello'] = 1; will work like you expect.

However, when you overload the offsetGet method, you CANNOT define it as &offsetGet, so the above code falls out (because it returns the 'foobar' variable before you actually work with it).

This is something that the developers broke between 5.0 and 5.1, and was closed as bogus (http://bugs.php.net/bug.php?id=34783). So this is not a big, or question, or request, but just something worth noting.
up
-1
Alex Andrienko
4 years ago
Speaking of offsetGet() method overloading, be advised, that if you're iterating through Object via foreach, this method wouldn't be called. Iterator's current() method will be called instead.

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