You are here: Re: accesing to members of objects « PHP Programming Language « IT news, forums, messages
Re: accesing to members of objects

Posted by Jerry Stuckle on 01/19/06 14:11

julian_m wrote:
> A short piece of code which i'm having problems with:
>
> class ClsX{
>
> var $F_name;
> var $F_array_of_obj= array();
>
> function ClsX(&$obj, $name){
> //Here I add an object reference to an array. Note that all objects
> inside $F_array_of_obj will be of X class or null values
> $this->F_array_of_obj[] = $obj;
> $this->F_name = $name;
> $this->ListParents();
> }
>
>
> function ListParents(){
> foreach ($this->F_array_of_obj as $obj) {
> echo "Te name of the parent is: ". $obj->F_name;
> }
> }
> }//class
>
>
> $clsX1 = new ClsX("","name1");
>
> $clsX2= new ClsX($clsX1, "name2");
>
> I thought that this code would output
>
> "the name of the parent is name1"
>
> but it actually prints
>
> ""the name of the parent is"
>
> so the problem is that I can't acces to de object's data inside the
> array.
> Any hints?
>
> regards - jm
>


Do you have error reporting enabled? Which version of PHP?

On 5.0.3 I get:

Fatal error: Cannot pass parameter 1 by reference in H:\temp\test.php on
line 25

This is referencing the line:

$clsX1 = new ClsX("","name1")

Which is valid - "" isn't a variable, so you can't reference it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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