Background
The Zend Engine 1.0 introduced the ability to call class methods via the class name,
instead of using an object instance (e.g. class_name::method()). However, there is no
way to access class-specific variables using a similar notation. As a matter of fact,
classes in the Zend Engine 1.0 don’t have any storage of class-specific variables.
Need
Very often, it is desirable to store information that is only relevant to a specific class. In
version 1.0, there’s no good way of doing that, other than using a global variable, usually
with an appropriate prefix that would avoid collisions with other global variables.
Overview
Version 2.0 will introduce class-local variables – variables which belong to a specific
class. The syntax for accessing these variables will be similar to that of accessing class
methods via the class name.
Functionality
For example, if you wish to implement a singleton class:
class Logger {
static $m_Instance = NULL;
function Instance()
{
if (Logger::$m_Instance == NULL) {
Logger::$m_Instance = new Logger();
}
return Logger::$m_Instance;
}
function Log(){
…
}
};
$Logger = Logger::Instance();
$Logger->Log(…);
Compatibility notes
No compatibility issues
Dependencies of feature
No dependencies.