You are here: Re: Fatal error: Call to a member function on a non-object « All PHP « IT news, forums, messages
Re: Fatal error: Call to a member function on a non-object

Posted by Steve on 03/01/07 17:58

<laredotornado@zipmail.com> wrote in message
news:1172770679.377598.207250@z35g2000cwz.googlegroups.com...
| On Mar 1, 11:28 am, "Steve" <no....@example.com> wrote:
| > <laredotorn...@zipmail.com> wrote in message
| >
| > news:1172766345.255553.20170@v33g2000cwv.googlegroups.com...
| > | Hi,
| > |
| > | Using PHP 4.4.4, and I have this class
| > |
| > | class CUserItem {
| > | var $m_id;
| > | var $m_children_arr;
| > | function CUserItem($p_id)
| > | {
| > | $this->m_id = $p_id;
| > | $this->m_children_arr = array();
| > | } // CUserItem
| > | function addChild($p_child) {
| > | array_push($this->m_children_arr, $p_child);
| > | } // addChild
| > | function numChildren() {
| > | return count($this->m_children_arr);
| > | } // numChildren
| > | } // CUserItem
| > |
| > | I have an associative array of objects, but am getting errors trying
| > | to call a method
| > |
| > | $items_arr = array();
| > | $items_arr[0] = new CUserItem(1);
| > | $item = &$items_arr[0];
| > | print $item->numChildren(); // produces an error
| > |
| > | The error produced is "Fatal error: Call to a member function on a
non-
| > | object in /usr/local/apache2/htdocs/portal/show_toc.inc on line 77".
| > | I need to get the object by reference because I will be manipulating
| > | it later on. What am I doing wrong above?
| >
| > print_r on $items_arr[0], then print_r on $item after it is set by ref
to
| > $items_arr[0]. finally print_r on $item after $item is set to
$items_arr[0]
| > by value. therein lies the difference.
|
|
| Thanks for your reply but I don't understand what you are asking me to
| do. Could you provide a code sample? I want "$item" to contain a
| reference ot the created object (as opposed a new copy) but I would
| then like to call a method from the object being referenced.

$items_arr = array();
$items_arr[0] = new CUserItem(1);
$itemTestA = &$items_arr[0];
$itemTestB = $items_arr[0];
$test = array(
'RAW DATA' => $items_arr ,
'BY REF' => $itemTestA ,
'BY VAL' => $itemTestB
);
print_r($test);

see what the differences are. does that 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

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