473,396 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

accesing to members of objects

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

Jan 19 '06 #1
3 1224
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.
js*******@attglobal.net
==================
Jan 19 '06 #2

Jerry Stuckle wrote:
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.


Well, actually I've solved the problem that I had

for ($i = 1; $i <= count($this->F_array_of_obj); $i++) {
$object = $this->F_array_of_obj[($i-1)];
$object->WhatEverObjectFunction();
}

Note that I come from a Delphi background, where all object call should
be preceded by a typecast. I mean:
TYPEOFOBJ($object)->WhatEverObjectFunction();
In this way, I'm saying "i'm sure that $object has a function named
WhatEverObjectFunction()"

BTW, What happens if $object doesn't has WhatEverObjectFunction()?

regards - jm

Jan 19 '06 #3
julian_m wrote:
Jerry Stuckle wrote:
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.



Well, actually I've solved the problem that I had

for ($i = 1; $i <= count($this->F_array_of_obj); $i++) {
$object = $this->F_array_of_obj[($i-1)];
$object->WhatEverObjectFunction();
}

Note that I come from a Delphi background, where all object call should
be preceded by a typecast. I mean:
TYPEOFOBJ($object)->WhatEverObjectFunction();
In this way, I'm saying "i'm sure that $object has a function named
WhatEverObjectFunction()"

BTW, What happens if $object doesn't has WhatEverObjectFunction()?

regards - jm


You get a run-time error and processing of the php stops.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jan 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Luther Baker | last post by:
Hi, Is the order of initialization guaranteed for static members as it is for instance members? Namely, the order they appear the in the declaration? ie: foo.h:
0
by: Cat | last post by:
I have class Base, and class Derived. I am serializing Derived objects from XML, and these Derived objects are allowed to 'inherit' the values from other named Base objects already defined in...
16
by: Crirus | last post by:
I have a class. I need to write a routine in this class, that loop through it's members (in a instance of the class) and concatenate all members values as string. I need to filter does members...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
2
by: ras26 | last post by:
I have a WebSite "App1" which has an external assembly "Lib1". Inside this external assembly we have developed some classes that derive from "System.Web.UI.Page". One of these pages is called...
4
by: sracherla | last post by:
Hello Guys, Please look at the code sample below. Class Customer { private string _ID; private string _Name; public string ID
18
by: lovecreatesbea... | last post by:
1. The following code snippet uses minus operation on two pointers to calculate the distance between struct members. This is illegal, right? 2. s1 and s2 are type of the same struct S. Can the...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
5
by: Andy B | last post by:
I have a class that I want to make static but it uses some objects that are instance objects. I keep getting a compiler error saying something about using instance objects in a static class or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.