You are here: Re: Problem retrieving an object from an array and calling a method on the object « PHP Programming Language « IT news, forums, messages
Re: Problem retrieving an object from an array and calling a method on the object

Posted by ZabMilenko on 10/08/06 01:04

Try this:

$day_object =& $this->array_of_days[$index];
$day_object->addEvent($event);


Notice the ampersand next to the equals sign.


Also, comment out this "$day_object->addEvent($event);" and do this:

print '<pre>' . print_r($day_object, true) . '</pre>';

To get an idea of what might be there, if you are curious.



Jayman777@gmail.com wrote:
> Hello, I am using PHP 4.4.1 and am having problems retrieving an object
> from an array of objects and then calling a method on it. Here are two
> simple classes that I am using:
>
>
>
>
>
> class Day
> {
> var $day;
> var $array_of_events;
>
> function Day($in_ts)
> {
> $this->day = getdate($in_ts);
> }
>
> function addEvent($in_event)
> {
> $this->array_of_events[] = $in_event;
> }
> }
>
> class Event
> {
> var $event_id;
> var $begin_time;
> var $end_time;
> var $summary;
> var $description;
> var $category;
>
> function Event($in_id, $in_begin_time, $in_end_time, $in_summary,
> $in_description, $in_category)
> {
> $this->event_id = $in_id;
> $this->begin_time = $in_begin_time;
> $this->end_time = $in_end_time;
> $this->summary = $in_summary;
> $this->description = $in_description;
> $this->category = $in_category;
> }
> }
>
>
>
>
> The problem arises in another class's function with the following code:
>
>
>
>
> $this->array_of_days = array();
> for ($i = 1; $i < num_days_in_month + 1; $i++)
> {
> $this->array_of_days[$i] = new Day(mktime(00, 00, 00, $in_date['mon'],
> $i, $in_date['year']));
> }
> /* Unrelated code */
> $day_object = $this->array_of_days[$index];
> $day_object->addEvent($event);
>
>
>
>
> The program creates an error on the last line of the last code snippet.
> My web host does not print out the error message so I don't know
> exactly why it fails. I'm sure it has something to do with getting an
> object from an array because I tried to call the addEvent function on a
> Day object that was not retrieved from an array and it works fine.
>
> Does anyone have an idea what the problem is? Thank you for any help.
>

 

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

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