I would like to apologize in advance: I’m not a Portuguese speaker, I’m just using Google Translate to translate my answer.
As other people have indicated that you seem to be reading the documentation for Silex 1.x, but what you have installed is Silex 2.x.
One of the main differences between the two versions is that the dependency injection container that Silex uses - Pimple - was incorporated into Silex itself in 1.0, while in 2.0 it is treated as a separate application (and probably this is a good idea). Share
is actually a Pimple method, not a Silex method.
Well, I say it’s a Pimple method ... era a Pimple method. In Pimple 1.x, all dependencies were transient objects, unless the method was specifically used share
to make it a Singleton. In the current version of Pimple (3.x), the default has been changed and all dependencies are automatically singletons by default, so the method share
is redundant.
What you need to do is follow the Silex 2.x and Pimple 3.x documentation when configuring your application.
References:
(Silex 1.x / Pimple 1.x) By default, each time you receive a service, Pimple returns a new instance. If you want the same instance to be returned for all calls, involve your anonymous function with the method share()
(Silex 2.x / Pimple 3.x) By default, each time you receive a service, Pimple returns the same instance.
There is no such method implemented here. Are you sure you have installed the correct version of the library?
– Woss
@Andersoncarloswoss So I went to Composer require Silex/Silex and returned to me: Nothing to install or update
– Igor De Assis Pires
Your problem is version itself. You took this code from one version and installed another. See this related question in Soen: https://stackoverflow.com/q/28163693/1452488.
– Woss