473,400 Members | 2,163 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,400 software developers and data experts.

Classes Can't Contain Object Members?

Using PHP 4.3.3; I'm trying to write a class that has as a member an
instance of another class. Assume class B is already written and supports
the method "method()".

class A {
var _desc;
var _obj;

function A() {
$this->_desc = "Desc test";
$this->_obj = new B();
$this->_obj->method(); // Works here
}

function helper() {
$this->_obj->method(); // Parse error claiming that I'm calling a
member function on a non-object
return;
}
}

Is this not possible in PHP? Is there another way?

Help appreciated,

Derek
Jul 17 '05 #1
2 1780
Yeah it is possible @ least i use it this wayi can't see the problem
maybe this will work:
class A {
var _desc;
var _obj;

function A() {
$this->_desc = "Desc test";

$this->_obj->method(); // Works here
}

function new obj()
{
$this->_obj = new B();
}

function helper() {
$this->_obj->method();
}
}

i dunno maybe try a older version of php i my self use 4.3.2 and so
think simular works there

On Sat, 11 Oct 2003 20:42:16 GMT, "Derek Battams"
<de***@stopspam.battams.ca> wrote:
Using PHP 4.3.3; I'm trying to write a class that has as a member an
instance of another class. Assume class B is already written and supports
the method "method()".

class A {
var _desc;
var _obj;

function A() {
$this->_desc = "Desc test";
$this->_obj = new B();
$this->_obj->method(); // Works here
}

function helper() {
$this->_obj->method(); // Parse error claiming that I'm calling a
member function on a non-object
return;
}
}

Is this not possible in PHP? Is there another way?

Help appreciated,

Derek


Jul 17 '05 #2
sam
"Derek Battams" <de***@stopspam.battams.ca> wrote in message
news:13******************************@news.teranew s.com...
Using PHP 4.3.3; I'm trying to write a class that has as a member an
instance of another class. Assume class B is already written and supports
the method "method()".

class A {
var _desc;
var _obj;

function A() {
$this->_desc = "Desc test";
$this->_obj = new B();
It works fine for me with the reference operator:
$this->_obj = &new B();
$this->_obj->method(); // Works here
}

function helper() {
$this->_obj->method(); // Parse error claiming that I'm calling a
member function on a non-object
No error if you do as I said before.
return;
}
}

Is this not possible in PHP? Is there another way?

Help appreciated,

Derek

Jul 17 '05 #3

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

Similar topics

3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
30
by: Frank Rizzo | last post by:
We are having one of those religious debates at work: Interfaces vs Classes. My take is that Classes give you more flexibility. You can enforce a contract on the descendant classes by marking...
3
by: WithPit | last post by:
I am trying to create an managed wrapper but have some problems with it by using abstract classes. In my unmanaged library code i had the following three classes with the following hierarchy ...
6
by: David Lozzi | last post by:
Howdy, I'm new to classes. Below is my class User. (is this a reserved namespace or class?) It works great, kind of. If I specify the username and password, the correct firstname and lastname...
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...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
5
by: =?Utf-8?B?UmljaA==?= | last post by:
Greetings, I am actually a VB.Net guy, but I have worked somewhat with C++ and C#. I just want to ask about the relationship between Abstract Classes and Interfaces. My first question is if...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
3
by: puzzlecracker | last post by:
Would you quickly remind me the difference between, regular class, static class, and nested class? Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.