You are here: array_keys with objects « PHP Programming Language « IT news, forums, messages
array_keys with objects

Posted by Tamlyn Rhodes on 06/15/05 04:15

I have a gallery object which contains an array of image objects. I
would like the image objects to be able to return their adjacent
siblings in the array so that, for example,
$gallery->images[3]->nextImage() would return $gallery->images[4]. The
images each contain a reference to their parent (i.e. the gallery
object) so I tried using array_keys(). This is a method of the image class:

function nextImage() {
$pos = array_keys($this->parent->images, $this);
return $this->parent->images[$pos[0]+1];
}

The array_keys call *should* find the current object ($this) in the
array and return an array containing a single value which is the index
of the current image in the images. But instead I get "Fatal error:
Nesting level too deep - recursive dependency?"

I suppose this has something to do with the cyclic references. Can
anyone suggest a way around this or any other way for an image to access
it's siblings?

Thanks,

T.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация