28

Once

  1. Object
    1. Once

A Once class creates only one instance.

CLASS METHODS

  1. namespace Once;
  2.  
  3. require_once 'So-o.php';
  4.  
  5. defclass('Once', null, 1, array('instance'), null, array('new'), null);

The Once class inherits from the Object class. The class property instance keeps the unique instance of the class. The Once class redefines the class message new.

new
SYNOPSIS

sendmsg($class, 'new'[, $arg ...])

DESCRIPTION

The first time new is called, it returns a new instance of $class. The following times, it returns this same instance of $class.

new passes all the $arg parameters of the message to init.

CODE
  1. namespace Once;
  2.  
  3. require_once 'So-o.php';
  4.  
  5. defclass('Once', null, 1, array('instance'), null, array('new'), null);

The Once class inherits directly from the Object class. It keeps the only instance it creates in the class property instance. It redefines the class message new.

  1. function c_new($self) {
  2.     $i=sendmsg($self, 'get', 'instance');
  3.  
  4.     if (!$i) {
  5.         $i=supersend('new', func_get_args());
  6.         sendmsg($self, 'set', 'instance', $i);
  7.     }
  8.  
  9.     return $i;
  10. }

new retrieves the class property instance. If this property has no value yet, new creates a new instance by calling the new method inherited from the Object class with all the arguments of the message and saves the new instance in the class property instance. new returns the instance which was saved or the new instance.

SEE ALSO

Application

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].