After PHP5, a series of predefined interfaces are added, collectively known as SPL, for these interfaces and implemented classes. These interfaces have a heavyweight interface arrayaccess, which is used to make your object accessible like an array.
interface introduction, using the Arrayaccess method requires the definition of four methods.
arrayaccess { /* Methods * * Abstract public boolean offsetexists (mixed $offset) abstract public mixed OFFSE Tget (mixed $offset) abstract public void Offsetset (mixed $offset, mixed $value) abstract public void offset Unset (mixed $offset)}
The specific implementation of the interface in Slim is given below. A collection class collection is defined in slim, which provides a common interface method for collection objects. Where this class inherits the Collectioninterface interface, it inherits the Arrayaccess predefined interface.
/*** the collection interface, passing in an array in the container's settings, returning a collection object. * Collection interfacecollectioninterface* @package slim* @since 3.0.0 */interface collectioninterface extends \ Arrayaccess, \countable, \iteratoraggregate{public function set ($key, $value); Public function Get ($key, $default = null); Public function replace (array $items); Public function All (); Public function has ($key); Public function Remove ($key); Public function Clear ();} Say, slim framework of the collection class. After merging the container's default configuration $defaultsetting (private variable of the class) and the User Configuration $usersetting (log, template, database configuration, etc.) in Slim container Contianer, a Collection object collection is returned. Since the collection object inherits Arrayaccess, we can manipulate the configuration file as if it were an array after loading it sequentially.
This article explains the PHP pre-defined interface of the use of arrayaccess, this method in PHP has an important role, more relevant content please pay attention to the PHP Chinese web.