473,670 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class can not inherit from another class, why ?

Is this a valid class definition?

class McBase {

// 06-14-04 - I may or may not later add something here. This will
// be the top of the PDS content management system hierarchy. I'm
// leaving it blank for now but want it here for future flexibility.

}


I use it later on this line:

class McBasic extends McBase {
but I get this error:

Fatal error: Class mcbasic: Cannot inherit from undefined class mcbase
in /usr/local/www/vhosts/publicpen.com/htdocs/designer/ppKernel/McBasic.php
on line 5
Jul 17 '05 #1
6 2146
.oO(lawrence)
Is this a valid class definition?

class McBase {
[...]
Yes.
I use it later on this line:

class McBasic extends McBase {
but I get this error:

Fatal error: Class mcbasic: Cannot inherit from undefined class mcbase
in /usr/local/www/vhosts/publicpen.com/htdocs/designer/ppKernel/McBasic.php
on line 5


The question is: Are both classes stored in the same file? Apparently
not. So you have to include the base-class before you can extend it,
e.g.

require_once 'mcbase.php';

class McBasic extends McBase {...}

HTH
Micha
Jul 17 '05 #2
Michael Fesser <ne*****@gmx.ne t> wrote in message
Fatal error: Class mcbasic: Cannot inherit from undefined class mcbase
in /usr/local/www/vhosts/publicpen.com/htdocs/designer/ppKernel/McBasic.php
on line 5


The question is: Are both classes stored in the same file? Apparently
not. So you have to include the base-class before you can extend it,
e.g.

require_once 'mcbase.php';


Thanks. Now I got it working. But McBasic doesn't seem to have its
constructor called when it is the parent of another class. I've been
trying to test, as you'll see here:

class McBasic extends McBase {
var $controllerForA ll = null;
var $resultsObject = null;
var $notifyObject = null;
var $historyObject = null;

/**
*
*
* 06-14-04 - most objects in the PDS content management system should
be
* descended from McBasic. This provides basic servies to all its
child
* classes. All the classes that themselves contain no other objects
can
* safely be put here, and then become services available to all child
* classes.
*
*
*
*
*/
function McBasic() {
// a test for debugging
echo "hello<br>" ;
$this->controllerForA ll = & getController() ;

if (is_object($thi s->controllerForA ll)) {
echo "this is an object";
} else {
echo "this is not an object";
}
$this->resultsObjec t = &
$this->controllerForA ll->getObject("McR esults", " in the constructor
of McBasic.");
$this->notifyObject = &
$this->controllerForA ll->getObject("McN otify", " in the constructor of
McBasic.");
$this->historyObjec t = &
$this->controllerForA ll->getObject("McH istory", " in the constructor
of McBasic.");
}
}



But in the class McArrangements, I have this line:

class McArrangements extends McBasic {

Yes McArrangements throws an error whenever I use the 4 objects that
are set in the constructor of McBasic. The error says that there is no
such object. For instance, I get an error on this line in
McArrangements:

$this->resultsObjec t->error("In setControlPanel CbId(), in the class
McArrangements, we expected the method's parameter to be a number, but
instead we got this: $cbId ", "McArrangements ");
So I decided to write a test for McBasic, and the test revealed that
everything was working for McBasic. In the test, I call McBasic
directly, and at the end of the constructor I test to see if
$this->resultsObjec t is an object. It tests true. Yet when I refer to
$this->resultsObjec t in McArrangements, I get "No such object". How
can this be?
Jul 17 '05 #3
lawrence wrote:
Thanks. Now I got it working. But McBasic doesn't seem to have its
constructor called when it is the parent of another class. I've been
trying to test, as you'll see here:
<snip>
So I decided to write a test for McBasic, and the test revealed that
everything was working for McBasic. In the test, I call McBasic
directly, and at the end of the constructor I test to see if
$this->resultsObjec t is an object. It tests true. Yet when I refer to
$this->resultsObjec t in McArrangements, I get "No such object". How
can this be?


Are you using PHP5? Try using _construct().

According to the Zend articles, the old way of defining constructors should
work as well, but there might be some problems when calling parent's
contructor.

Berislav
Jul 17 '05 #4
Berislav Lopac wrote:
lawrence wrote:
Thanks. Now I got it working. But McBasic doesn't seem to have its
constructor called when it is the parent of another class. I've been
trying to test, as you'll see here:


<snip>
So I decided to write a test for McBasic, and the test revealed that
everything was working for McBasic. In the test, I call McBasic
directly, and at the end of the constructor I test to see if
$this->resultsObjec t is an object. It tests true. Yet when I refer to
$this->resultsObjec t in McArrangements, I get "No such object". How
can this be?


Are you using PHP5? Try using _construct().


Oops, that should be __construct() (two underscores).

Berislav
Jul 17 '05 #5
lk******@geocit ies.com (lawrence) wrote in message news:<da******* *************** ****@posting.go ogle.com>...
Michael Fesser <ne*****@gmx.ne t> wrote in message
Fatal error: Class mcbasic: Cannot inherit from undefined class mcbase
in /usr/local/www/vhosts/publicpen.com/htdocs/designer/ppKernel/McBasic.php
on line 5


The question is: Are both classes stored in the same file? Apparently
not. So you have to include the base-class before you can extend it,
e.g.

require_once 'mcbase.php';


Thanks. Now I got it working. But McBasic doesn't seem to have its
constructor called when it is the parent of another class. I've been
trying to test, as you'll see here:


[snip]

If you're running PHP 4+ and not PHP 5 use the parent keyword to run
the parent's constructor in the child's constructor:

[PHP]
class Parent {

function Parent() {
// DO STUFF HERE
}

}

class Child extends Parent {

function Child() {
parent::Parent( );
}

}
[/PHP]

Phil
Jul 17 '05 #6
so*****@erols.c om (Phil Powell) wrote in message news:<1c******* *************** ***@posting.goo gle.com>...
lk******@geocit ies.com (lawrence) wrote in message news:<da******* *************** ****@posting.go ogle.com>...
Michael Fesser <ne*****@gmx.ne t> wrote in message
>Fatal error: Class mcbasic: Cannot inherit from undefined class mcbase
>in /usr/local/www/vhosts/publicpen.com/htdocs/designer/ppKernel/McBasic.php
>on line 5

The question is: Are both classes stored in the same file? Apparently
not. So you have to include the base-class before you can extend it,
e.g.

require_once 'mcbase.php';


Thanks. Now I got it working. But McBasic doesn't seem to have its
constructor called when it is the parent of another class. I've been
trying to test, as you'll see here:


[snip]

If you're running PHP 4+ and not PHP 5 use the parent keyword to run
the parent's constructor in the child's constructor:

[PHP]
class Parent {

function Parent() {
// DO STUFF HERE
}

}

class Child extends Parent {

function Child() {
parent::Parent( );
}

}
[/PHP]

Phil


The parent keyword! I'd never heard of that! That is a terrific tip,
thanks much.

I got it work like this: McArrangements had a constructor that wasn't
doing much, just setting a variable that could be set elsewhere. So I
rewrote it and deleted the constructor. Suddenly the constructor of
McBasic was called. So, I reasoned, if you want to have the
constructor of a parent class called, you are not allowed to have a
constructor in the child class. But now I see that, quite reasonably,
there is a way to call parent constructors, and still have the child
have a constructor. Very good!
Jul 17 '05 #7

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

Similar topics

3
5136
by: nikolai.onken | last post by:
Hello, I got following problem trying to inherit a variable from another class class Core { public $obj; function initialize($obj) {
15
2405
by: Tee | last post by:
Hi, I have a base usercontrol with a method (blank method, no code), I have another few usercontrols that will inherit this base usercontrol, but I want to force all the usercontrol that inheriting this base usercontrol to override the method with its own code. How do I do it? I have tried to make the base usercontrol an abstract class (mustinherits + mustoverrides), this works, but all the usercontrols that inherit it will not able...
9
4989
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class pointer which points to an instance of a derived class, but when I pass that base class pointer into a function, it can't access the derived object's public functions. Although, the base class pointer does call the appropriate virtual function...
5
8727
by: Chris | last post by:
Hi, I don't get the difference between a struct and a class ! ok, I know that a struct is a value type, the other a reference type, I understand the technical differences between both, but conceptually speaking : when do I define something as 'struct' and when as 'class' ? for example : if I want to represent a 'Time' thing, containing : - data members : hours, mins, secs
3
3364
by: Peter Cresswell | last post by:
Hi guys/gals, I'm using VS.net 2003 and having trouble with the following: I am trying to inherit a base class into a web form, but VS will then not allow me to add any ASP.NET controls using the designer. The base class does derive from System.Web.UI.Page. Here's a code snippet:
3
1411
by: David Lozzi | last post by:
Howdy, I've discovered how to create and use a class in ASP.NET. However, when is the best time to use a class? For example, I am currently using session variables to store user information (user id, user name, full name, security level, department, etc.). Would I do better to create a class instead? Also, if I did, would I simply store the ID in the session and when accessing the class (User.FullName, User.SecurityLevel, etc.) then check the...
6
3987
by: rupertgalea | last post by:
I have a bunch of web services that are used to return data. All of the methods access a DB to get the data. Ideally I would like to have them inherit from a base class that takes care of the DB connection and exception logging. By default in VS.NET all web service classes inherit from System.Web.Services.WebService. My understanding is that the main benefit of this is you get access to the Application and Session objects. But a web...
12
6494
by: jarradw | last post by:
I am trying to figure out if this will work. I have a template base class that I want to be able to inherit from, the classes that will need to inherit from this also need to be tamplates. Is this possible or do i need to think of another way to do it?
4
1846
by: kikazaru | last post by:
Can I write methods in one class A, that use methods in another base class B, in such a way that I can make a class C1 that inherits A and B1 (a child of B) so that the methods in A use the implementations of B's methods provided by B1? (And also make C2 inheriting A and B2 (another child of B) and C3 etc.). Is it possible to do this entirely with inheritance, or do you have to store a pointer to a class of type B in A in order to get this...
26
5357
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is because I am not always able to control/create all the different constructors the base class has. My problem can be described in code as follows ... /* This is the base class with a whole heap of constructors/functionality*/ public class Animal
0
8388
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8817
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8593
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7423
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6218
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5687
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4396
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1799
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.