L
L
Lander2015-09-25 13:04:45
PHP
Lander, 2015-09-25 13:04:45

What is the essence of the design and how is this possible?

Good afternoon. Absolutely stupid question, but not out of my head.
I am picking the source code of Slim Framework. Found the design:

$this->container = new \Slim\Helper\Set();
$this->container['settings'] = array_merge(static::getDefaultSettings(), $userSettings);

How can you assign an object to a class member, and then work with it as an array? There are no magic methods in \Slim\Helper\Set. Shed some light on the situation, please. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-09-25
@usdglander

class Set implements \ArrayAccess, \Countable, \IteratorAggregate

The point is that this class implements the ArrayAccess interface .
PS
Also available - https://github.com/slimphp/Slim/blob/2.x/Slim/Help...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question