PHP Classes


Recommend this page to a friend!
  Classes of Thomas Björk   LOCO   Download  
Role: Auxiliary data
Content type: text/markdown
Description: New readme in markdown
Class: LOCO
Queue actions on objects to be performed later
Author: By
Last change: Update of
Date: 2 days ago
Size: 3,906 bytes


Class file image Download


Base class for LOCO functionality. The class LOCO has not much separate logic and is just a collector for all calls and variable set calls.


The first argument in the constructor is the class that should be used when executing the actions.


The first argument in this call is the function that should return a value when executing the actions later. The __lococall returns an array containing all actions stored in LOCO.


Tells LOCO to include a specific file at runtime.


Extends the basic LOCO class by adding two static functions.


Executes an array of actions (that you get from __lococall)


Loads the specified file and then calls Execute


A more stand-alone extension of the LOCO class adding the special functions __locogo, __locoobject, __locoget, __locoset, __locosave and __locoload.


Executes the stored actions. The return value of the last call is used as a return value for this function.


Returns the object used by LOCO internally.


Get the list of actions.


Set a new list of actions.


Save the list of actions to a file.


Load a new list of actions from a file.

When to use LOCO?

LOCO can be used to decrease the execution time for a request by extracting tasks that are heavy time consumers to an external task, for instance a cronjob, without the need for the new context to know any context specific information about the old context. An example is to send mail from the web server to the webmaster without putting any delay to the request.

In file where you wish to send a mail but doesn't bother if it filed or not. (Note that you does not have to include PHPMailer in this file. This is because it is never actually called.)

$mail = new GoLOCO('PHPMailer');
$mail->AddAddress('', 'Thomas');
$mail->Subject = 'GoLOCO test';
$mail->Body = 'This mail is sent by using <strong>GoLOCO</strong>';

Then there might be a cronjob running in the background calling another file containing this code:

$send = new GoLOCO();


Demo 1

A rather complicated way to create an object from the class Test, setting the $value to a value and then print the $value.

// demo1.php
class Test {
  var $value;

$gl = new GoLOCO('Test');
$gl->value = 42;
$actions = $gl->__locoget();

$gl2 = new GoLOCO();
$test = $gl2->__locoobject();

echo $test->value;
echo "\n";

Should print out 42

Demo 2

Simple way to include at time of execution. The basic function is Demo 1 but split into three files

// demo2a.php
class Test {
  var $value;

// demo2b.php
$gl = new GoLOCO('Test');
$gl->value = 42;

// demo2c.php
$gl = new GoLOCO();
$test = $gl->__locoobject();
echo $test->value;

Running demo2b.php followed by demo2c.php should print out 42

The script demo2b.php generates a file called demo2.loco that contains the actions performed in demo2c.php.

Demo 3

// demo3.php
class Test {
  var $value;
  public function ShowValue() {
    echo $this->value;

$gl = new xLOCO('Test');
$gl->value = 42;
$actions = $gl->__lococall('ShowValue');