noloh Logo SmallDeveloper Zone
Username:
Password:
remember meforgot password?Login
twitterfacebookirc
plusfolder closePrinciples
plusdocumentWhat is NOLOH?
plusdocumentWhat's so Bad About Markup?
plusdocumentDevelopment and Philosophy
plusfolder closeFeatures
plusdocumentSyntactical Sugars
plusdocumentMultiple Inheritance
plusdocumentBookmarks and NOLOH
plusdocumentUser State Management
plusdocumentSearch Engine Friendly
plusfolder closeGetting Started
plusdocumentPHP and NOLOH Syntax
plusdocumentHello World
plusdocumentConstructors
plusdocumentInstalling NOLOH
plusfolder closeCrash Course
plusdocumentNOLOH and CSS
plusdocumentLayout in NOLOH
plusdocumentDatabases
plusdocumentData::$Links
plusdocumentEvents in NOLOH
plusdocumentMoving and Resizing Your Objects
plusdocumentMultiple Inheritance
plusdocumentBookmarks and NOLOH
plusdocumentData Binding
plusfolder closeAdvanced Topics
plusdocumentCustom Events
plusdocumentClientside Functions
plusfolder closeSyntactic Sugars
plusdocumentSyntactical Sugars
plusdocumentCascading
plusfolder closeCoding Guidelines
plusdocumentBest Practices
plusdocumentNOLOH Naming Conventions
Syntactical Sugars
Syntactical Sugarsoverviewdiscussion

NOLOH has numerous syntactical sugars, many of which were laboriously implemented to provide an easy and intuitive experience. Some syntactical sugars allow for a consistent use of PHP syntax, while others are more notable and are mentioned in this document.

Ability to call Get or Set Functions as Properties

Any function whose name is prefixed with "Get" or "Set" can alternatively be called as a property, provided that there is no class variable of the same name which can also be accessed. This allows for a developer to write code that responds to retrieving or assigning properties, but keep the simple and easy-to-read notation of variables. This can used for, but is not limited to, validating input, computing live results rather than storing them, or even for overloading the default behavior of some NOLOH properties.

class TestObj extends Panel
{
    private $SomeProperty;
 
    function TestObj()
    {
        parent::Panel();
    }
    //This is a Get function, that in this case returns the SomeProperty variable of TestObj
    function GetSomeProperty()
    {
        return $this->SomeProperty;
    }
    //This is a Set function, that in this case sets the SomeProperty variable of TestObj
    function SetSomeProperty($someValue)
    {
        $this->SomeProperty = $someValue;
    }
}

So, if you had an instance of the above TestObj, you could call the GetProperty and SetProperty functions as follows.

$test = new TestObj();
$test ->SomeProperty = 2;
$property = $tmpObj->SomeProperty; //this line will set $property to 2;
//The ability to call Get and Set functions as properties allows for easy chaining.
$property = $test->SomeProperty = 2;
//In the above example BOTH $property, and $test's SomeProperty member will be 2

Furthermore, you can even chain these Get or Set Properties as follows:

$test = new TestObj();
$test->SomeProperty = new TestObj();
//You could do the following
$test->SomeProperty->SomeProperty = 2;
/*The first SomeProperty returns the TestObj you just created.
It then sets the SomeProperty member of that TestObj to 2.*/

Ability to Modify an ArrayList With Square Brackets

Similar to an array, NOLOH allows you to use ArrayLists as though they were actual PHP arrays.

$arr = new ArrayList();

You can add to the ArrayList through the Add function

$arr->Add("something");

or you can add as if it were an array.

$arr[] = 2;

or use non-numerical indices

$arr[0] = 2; 
$arr['idx'] = 2;

This is also true for ArrayLists such as the Controls ArrayList of a Panel. You can do:

$panel = new Panel();
//To add you can do any of the following
$panel->Controls->Add(new Button("SomeButton");
$panel->Controls[] = new Button("AnotherButton");
$panel->Controls[0] = new Button("OtherButton");
$panel->Controls['idx'] = new Button("LastButton");

You can immediately see how the above is helpful if you wanted to add via a loop, or through a foreach. If you give the index an identifier such as idx you can immediately retrieve that element through that index rather than having to do a search through the ArrayList.

Consider the following search, which also demonstrates iterating through an ArrayList using a foreach construct:

foreach($panel->Controls as $control)
{
    if($control->Text == "LastButton")
    {
       $found = $control;
       break;
    }
}

Or using a string as an associative index

if(isset($panel->Controls["idx"]))
    $found = $panel->Controls["idx"];

You can immediately see how the second example is significantly faster than the first. Instead of looping through elements, you can immediately return what you want.

smallarrow
explanation arrowtool tip
handlebgexpand left
Right Up Outer CornerRight Down Outer CornerLeft Up Outer CornerLeft Down Outer Cornersearch-bottomclassconstantpropertymethodarticle
controltabsearchbig