473,396 Members | 1,799 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.

extending classes and constructors...

Hi...

Consider the following code:

-----8<-----8<-----8<-----8<-----

class A
{
var $str_text;

function A()
{
echo "Class A, constructor A";
$this->str_text = "I am in class A";
echo "A: $this->str_text";
}
}

class B extends A
{
var $str_more_text;

function B()
{
echo "Class B, constructor B";
$this->str_more_text = "I am in class B";
var_dump($this->str_text);
var_dump($this->str_more_text);
}
}

$cls_new = new B;

----->8----->8----->8----->8-----

The constructor for A is not called. Is it possible to call the constructor
of the parent class? I have an extended class that is dependant on data
mined in the parent class's constructor...

Plankmeister.
Jul 17 '05 #1
2 1500
The Plankmeister wrote:
Hi...

Consider the following code:

-----8<-----8<-----8<-----8<-----

class A
{
var $str_text;

function A()
{
echo "Class A, constructor A";
$this->str_text = "I am in class A";
echo "A: $this->str_text";
}
}

class B extends A
{
var $str_more_text;

function B()
{
echo "Class B, constructor B";
$this->str_more_text = "I am in class B";
var_dump($this->str_text);
var_dump($this->str_more_text);
}
}

$cls_new = new B;

----->8----->8----->8----->8-----

The constructor for A is not called. Is it possible to call the constructor
of the parent class? I have an extended class that is dependant on data
mined in the parent class's constructor...

Plankmeister.


http://us3.php.net/manual/en/keyword.parent.php?

Jul 17 '05 #2

"Keith Bowes" <do****@spam.me> wrote in message
news:x9*****************@fe01.usenetserver.com...
The Plankmeister wrote:
Hi...

Consider the following code:

-----8<-----8<-----8<-----8<-----

class A
{
var $str_text;

function A()
{
echo "Class A, constructor A";
$this->str_text = "I am in class A";
echo "A: $this->str_text";
}
}

class B extends A
{
var $str_more_text;

function B()
{
echo "Class B, constructor B";
$this->str_more_text = "I am in class B";
var_dump($this->str_text);
var_dump($this->str_more_text);
}
}

$cls_new = new B;

----->8----->8----->8----->8-----

The constructor for A is not called. Is it possible to call the constructor of the parent class? I have an extended class that is dependant on data
mined in the parent class's constructor...

Plankmeister.


http://us3.php.net/manual/en/keyword.parent.php?


Absolutely spot on. Ta muchly : )
Jul 17 '05 #3

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

Similar topics

1
by: f00sion | last post by:
I found a good tutorial of how to supply the objects without having the implementation files on the client. This was working great until I realized that I couldnt use any constructors with server...
6
by: Fred | last post by:
Hi I have a class defined in a library that I'd like to add some extra functionality to. This will involve adding a few member variables and a few related methods. As I understand it I can...
24
by: Alf P. Steinbach | last post by:
The eighth chapter (chapter 2.1) of my attempted Correct C++ tutorial is now available, although for now only in Word format -- comments welcome! Use the free & system-independent Open Office...
5
by: needin4mation | last post by:
Hi, I read this in a book about the Xml classes in c#: "These classes are abstract and therefore must be extended." I just wanted to know what this statement means. I know it is not in...
1
by: Sarge | last post by:
Hi all, tough question. Apologies for the cross posting but it is an interesting architectural problem and I think deserves a wide audience. What is the best way to extend web service proxy...
9
by: Fat Elvis | last post by:
I'd like to extend some of my Asp.net pages by using Partial Classes. Example ASP.Net Page: public partial class Admin_Customer : System.Web.UI.Page { protected void Page_Load(object sender,...
21
by: Daz | last post by:
Hi everyone. I am trying to create an extension of the mysqli class within PHP, and I am finding it quite difficult. I am fairly new to PHP classes, and decided to give them a go. Here's what I...
17
by: Jess | last post by:
Hello, If I have a class that has virtual but non-pure declarations, like class A{ virtual void f(); }; Then is A still an abstract class? Do I have to have "virtual void f() = 0;"...
7
by: Maximus Decimus | last post by:
HI all, I am using python v2.5 and I am an amateur working on python. I am extending python for my research work and would like some help and guidance w.r.t this matter from you experienced...
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....
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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
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,...

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.