In PHP 5, objects are automatically passed by reference
(although technically not the same as references, the effects are essentially the same).
??? ??? ??? ???
Getting Started
[ 28 ]
Inheriting from JObject
In Joomla! we often come across the class JObject. Many of the classes in Joomla!
are subclasses of JObject. This base class provides us with some useful common
methods including standard accessors and modifiers and a common error
handling mechanism.
To encourage PHP 5 methodology, JObject emulates the PHP 5 constructor allowing
us to use the constructor method, __constructor(), in subclasses irrespective of the
version of PHP is being used.
When we use inheritance in our classes we should, as a rule, always call the
constructor of the parent class. This guarantees that any construction work required
by a parent class is executed.
/**
* Some Class which extends JObject
*/
class SomeClass extends JObject
{
/**
* Object name
* @var string
*/
var $name;
/**
* PHP 5 style Constructor
*
* @access protected
* @param string name
Chapter 2
[ 29 ]
*/
function __construct($name)
{
$this->name = $name;
parent::__construct();
}
}
Nearly all Joomla! objects and classes derive from the base class JObject.
Pages:
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49