Interesting, but this happens also using a before Middleware, see below example.
So for me it is unclear which is the best way to share content between middlewares.
Usually an ingoing middleware is to check the incoming request object and an outgoing middleware is to change the response (object). So the shown example ExampleBeforeMiddleware in the documentation is quite confusing because it is an outgoing middleware.
If the response object is altered in the incoming middleware without actually returning a response from it, then changing something after the incoming middleware has no effect.
This is a bit strange, in this way there are a lot of cases where middlewares are unable to “communicate” with each other.
I changed the POC, editing the before middleware to use the altered request object, but also in this way I was unable to share data with the after middleware
In your case, it may depend on the order of the middleware stack. In Slim the middleware stack is LIFO (last in fist out). So the last middleware you add will be executed first. It’s not so easy to help here, because I don’t know much about your specific use case. Sorry.