phalcon/cphalcon — pull request #1935 by sjinks (2014-01-28 23:09:11+00:00)
Title: Phalcon\Registry

See #1209

A registry is a container for storing objects and values in the application space. By storing the value in a registry, the same object is always available throughout the application.

In addition to ArrayAccess, Phalcon\Registry implements ArrayAccess, Countable, Serializable and IteratorAggregate (can be iterated over using a foreach loop) interfaces. For PHP 5.4 and higher, JsonSerializable
interface is implemented.

Phalcon\Registry is very fast (it is typically faster than any userspace implementation of the registry); however, this comes at a price: Phalcon\Registry is a final class and cannot be inherited from.

Though Phalcon\Registry exposes methods like __get(), offsetGet(), count() etc, it is not recommended to invoke them manually (these method exists mainly to match the interfaces the registry implements): `$registry->__get('property')` is several times slower than `$registry->property`.

Internally all the magic methods (and interfaces except JsonSerializable) are implemented using object handlers or similar techniques: this allows to bypass relatively slow method calls.