I haven’t seen that second syntax used with the pimple container we currently use. Where’d you get it from?
Not sure if it’s valid, but if it is, one key difference would be that the first (official) syntax would only run the closure when the service is requested the first time. Your other syntax would run immediately.
Yikes, I don’t think that blog necessarily offers great advice I’d definitely use the expected syntax of providing the container with a callable to avoid side effects or unexpected behavior if we switch to a different container implementation later (i.e. php-di).
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.