Reply to Re: Adding a custom object to an array

Your name:

Reply:


Posted by Rik on 05/08/06 00:17

Areric wrote:
> Any idea why i cant add a custom object to an array then pull it back
> out and call a method?

<?php

class A{
var $elements = array();
var $count;
function A(){
$this->count = 0;
}
function add_element($text){
$object = new B($text);
$this->elements[$this->count] = $object;
$this->count++;
}
function return_element($int){
return $this->elements[$int];
}
}
class B{
var $text;
function B($var){
$this->text = $var;
}
function display(){
echo $this->text;
}
}

$test = new A();
$test->add_element("This works");
$test->add_element("Several times even");
$object = $test->return_element(0);
$object2 = $test->return_element(1);
$object->display();
$object2->display();
?>


Outputs: "This worksSeveral times even"

So, I think the problem would be elsewhere.
What do you see if you var_dump() your $album, or print_r($album->mImages),
before getting the image out? Does it really contain the object?

Maybe the Image class is only declared after the album has already tried to
add the images?

What happens if in the method you add the images, instead of
$this->mImages[$this->mImageCount] = $image;
return is_object($image):

Does it return false or true?


Grtz,
--
Rik Wasmus

[Back to original 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

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