{ :pop This JPopcorn is tasteful... }
The true meaning of $this statement is that I have no words to thank you all.
ianmac deep knowledge of the API is very precious, and his supervision and comments here are very good for everyone! Please, keep an eye and keep giving us some LIGHT!
And
AmyStephen´s skills to LIGHT our motivation are fantastic. (Are you a JMotivator instance?!)
Before going back to our subject, the
JObject class, let's exchange some words about OOP...
A class is a definition of a type of object. When a class is instantiated, you have an object of that class.
A class definition (a definition of the definition of an object) consists of the declaration of its properties (data) and methods (actions, or functions).
From "the outside", one may only grasp the interface (public properties and methods) and USE an object of a class. But from "the inside", it means, from the perspective of a developer who wishes to build new classes integrated with the already existent structure, or from the perspective of a joombie who dreams with being a Core Team member :laugh:, or simply confortably develop Joomla! websites knowing deeply what is happening and what he/she is doing, a knowledge about the BASE is encouraged because it will capacitate the developer to build his/her new classes following the patterns and standards used in the entire existing project - the Joomla-Framework, which is the engine behind the Joomla! CMS.
Well... I don't know yet the framework neither the API, but I am happy to share with you the results of my investigations!
Thank you, jalil, Rogue4ngel, matthewhayashida and all others to create and maintain 101!
As JObject is
ancestor of many many classes in the whole framework (all classes, Ian?), everything (properties and methods) declared in its definition will be
inherited, and, thus, accessible and usable by every
descendant class!
*** See Ian´s answer on post#21, where he also teaches some basic OOP concepts. ***As we saw, JObject offers a mechanism where you declare a __construct function to your JObject´s descendant class, and IT is the class constructor function even in PHP 4! Never need to bother with this tricky compatibility issue anymore! Just declare your custom class as JObject´s descendant (class MyClass extends JObject).
But this is only one feature. Let's continue and see the others?
Code:
function get($property, $default=null)
{
if(isset($this->$property)) {
return $this->$property;
}
return $default;
}
What
the documentation says about that?
Quote:
Returns a property of the object or the default value if the property is not set.
For instance: $object->get('property') or $butterfly->get('color') will return the $object->property value, or the $butterfly->color value. I can also define a default return value for the function, in case of the property wasn't set: $butterfly->get('color','blue') (see how it IS different from using $butterfly->color?). If the property was not set and I don't set a default value, the function will return null.
Now let's jump some lines in
object.php file, so we can learn a related function, as we can see below. (We should go back after.)
Code:
function set( $property, $value = null )
{
$previous = isset($this->$property) ? $this->$property : null;
$this->$property = $value;
return $previous;
}
[quote=∓quot;Documentation"\]Modifies a property of the object, creating it if it does not already exist.
return: Previous value of the property
[/quote]
This is simple (and powerful). Like love. For instance: $object->set('property','value') or $butterfly->set('color','violet') will set the $object->property value to 'value', or the $butterfly->color value to 'blue'. The return value for the function is the value of the property BEFORE the new value attribution (or null, in case of the property wasn't set).
So, $object->set('property', $object->set('property', $anything)) won't change the property and will return $anything! :laugh:
Curiously, $butterfly->set('color') will set the color property to null, as the second parameter is missing and its default value is null.
Now, you start to know what Johan carefully built for us.
Together, we will rise people's consciousness and save the planet! I don't eat meat nor sugar.