473,467 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

class inside another class - PHP 4

R
Hello.

I've got a strange situation.
I've got class Handlers it's only:

class Handlers
{
var $DB;
var $XML;
}

In my PHP script I want to do sth like this:

$Main = new Handlers();
$Main->DB = new DataBase();
$Main->XML = new XML();

but when inside eg. CreateNode method in XML class I want to run query
using: $this->DB->RunQuery();
it's of course fatal error...

I saw in one script that such classes
can be created but i don't remember where I found it...

Can it be writen in PHP 4?

thanks in advance

--
best regards
R
Jul 17 '05 #1
4 1813
R wrote:
using: $this->DB->RunQuery();

[...]

Can it be writen in PHP 4?


This works with PHP5. The solution for PHP4 is:

$db = &$this->DB;
$db->RunQuery();

Regards,
Matthias
Jul 17 '05 #2
Matthias Esken wrote:
R wrote:
using: $this->DB->RunQuery();

[...]

Can it be writen in PHP 4?


This works with PHP5. The solution for PHP4 is:

$db = &$this->DB;
$db->RunQuery();


There's nothing wrong with
$this->DB->RunQuery();
syntax in PHP4 as long as DB is a property and not a method.
Jul 17 '05 #3
.oO(Matthias Esken)
R wrote:
using: $this->DB->RunQuery();

[...]

Can it be writen in PHP 4?


This works with PHP5. The solution for PHP4 is:

$db = &$this->DB;
$db->RunQuery();


The above also works in PHP4. DB is a property, not a method.

The OP's problem is that $this always points to the object that calls
the method, inside the XML-methods it points to $XML, not to the parent
object. The XML-object can't directly access the methods of the DB-
object because it simply doesn't know about it.

One possible solution would be to implement a class method that returns
the required object:

PHP4:

$db = &Handlers::getInstance('DB');
$db->RunQuery();

PHP5:

Handlers::getInstance('DB')->RunQuery();

HTH
Micha
Jul 17 '05 #4
R
Zurab Davitiani wrote:
There's nothing wrong with
$this->DB->RunQuery();
syntax in PHP4 as long as DB is a property and not a method.


OK.

But I'm sure, that I saw in one PHP 4 script that such methods where used.
I used them by myself $this->Class1->ItsMethod() syntax inside eg.
$this->Class2->ItsMethod()

I used such object some time ago but I forgot the URL... I tried to
google but I failed

thanks in advance for Your help

--
best regards
R
Jul 17 '05 #5

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

Similar topics

2
by: Lüpher Cypher | last post by:
Ok, here's what I'm trying to do. I have a class. Inside the class I have a method that reads a text file. In the text file I have a class name and a file name where that class is defined. Now, I...
2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
13
by: Bryan Parkoff | last post by:
I have created three classes according to my own design. First class is called CMain. It is the Top Class. Second class and third class are called CMemory and CMPU. They are the sub-classes....
3
by: nicver | last post by:
I am fixing a client's Web site and for some reason an ASP class does not want to use the variables it retrieves when it initialiases. This is an excerpt of the class and it is enough to show...
12
by: Peter Cranz | last post by:
hello, I've got the following problem: I have a construct similar like this: namespace A { class X {
4
by: Miro | last post by:
Vb2003, im still learning vb.net but I do not understand my output from this logic. If someone can help me out here. Cor Ligthert, you I believe were on the right track of what Im trying to...
7
by: vabby | last post by:
Hi I have run into an eerie situation whihc i cant make out. I have a class A which has has two virtual functions with the same name, having diff arguments. Basically a case of function...
3
by: Stephen Torri | last post by:
Below is a class that is suppose to represent a segment of memory or a contents of a binary image (e.g. ELF executable). I have started to read Modern C++ Design and thought the best way to ensure...
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.