一个类如何同时成为一个数组和一个对象?

Reading this documentation of the Silex PHP micro-framework,

In the section

The service will now be registered in the application, and the convert method will be used as converter:

The code

$app['converter.user'] = $app->share(function () {
    return new UserConverter();
});

$app->get('/user/{user}', function (User $user) {
    // ...
})->convert('user', 'converter.user:convert');

$app is an array + an object at the same time. Or let's say it starts as an array but gets assigned an object. This confuses me: $app['converter.user'] =.

How does this work?

Using the PHP Iterator interface, as well as the ArrayAccess interface will allow PHP to know that your class can be treated as an array. One easy way to do this would be to extend from the ArrayObject class.

Essentially, what's happening with these interfaces is that you have a private variable, and methods on how to access that variable. The interfaces let PHP know that these methods exist, and that it can in fact treat the class as an array.

Now, if Silex uses this method or not, I can't comment. However, that is how you would create a PHP class that can also be accessed as an array

$app is not an array and an object. It is just an object, of which you can access the values through either the index or using the -> operator.

To answer your 2nd question, this is possible through overloading, which you can read here.