Defining Instances or Deriving Classes
Generally there are two possibilities to use a class:
Either you generate an instance of this class or you derive a further class from it.
Defining instances
You define an instance by declaring a variable:
myArticle = new PContentArticle ("Contact");
The article myArticle is initialised automatically by the constructor. You find more specific information in the description of the class PContentArticle. The constructor of PContentArticle also calls the constructor of the ancestor PContent which again calls the constructor of its ancestor PObject. Since PObject is the root object, the initialisation sequence ends at this object.
After the initialisation you can access data elements or methods of the object. In order to use myArticle you have to know the functionality of the available methods of the object and of its ancestor. If these properties and methods are not sufficient for your application, you have to derive a new object and define new functionalities.
Deriving classes
Deriving a new class is rather simple concerning the syntax:
class PNewArticle extends PContentArticle
{
}
Now you have defined a new object but it doesn’t differ in any way from its derivation object PContentArticle. Therefore you have to define new functions in your new class or to overwrite existing functions. You can - for instance - implement your own initialisations with a new constructor.
For further reference on instances and derivations please consult the website of the language PHP, or several portals and websites which deal with PHP more or less elaborately or the previous elaborate introductory tutorial to object-oriented programming in PHP in this documentation.
Continue to recommend this article:
|