Helix Installation   Getting Started   Reference Documentation   Global Functions   Quick Start
Getting StartedHelpful ResourcesAsk questions on the Help ForumRead the User GuideBrowse the Reference DocumentationSubscribe to the Helix Mailing ListLearning HelixAdvanced Topics

Public Property Accessors

One frustrating thing about PHP is the lack of property accessors found in other languages.  A property accessor is a member of class that looks like a property when used in the code, but internally calls a method in the class before returning the property value.

Helix makes property accessors available in PHP by using a clever combination of the PHP magic methods and class design protocols.  In order for Helix to implement property accessors in a class, the class has to extend the Helix obj class .

PHP Magic Methods

The PHP language uses a concept called magic methods in classes and objects.  Using the __get() and __set() magic methods, Helix calls certain methods of classes when properties are accessed in the code.

Helix Accessor Protocol

The Helix class design protocol says that all private and protected class properties should begin with an underscore character.  Then, when a property is accessed in code without the underscore, the PHP magic __get() method will look for a class method starting with get_ and ending in the property name.  When setting property values, the same thing is true except that the class will look for a method starting with set_.

For example, if you define a protected property called _name and a method called get_name, then when $object->name is used in the code, Helix will call the get_name() method for the value.

See the code below for an example of how to use public property accessors in Helix:

// Define a class with one protected property and a property accessor
class my_class extends obj
property $_name "Initial Name";
        public function 
"John Doe";
// Instantiate a new object of the class "my_class" and echo the name property
$object = new my_class();
// The echo statement above will echo "John Doe", and not "Initial Name"
Get Helix PHP Framework at SourceForge.net. Fast, secure and Free Open Source software downloads