Latelly I've been been looking more in depth into the framework and found this 
bug, or posible bug on applications running on ZendFramework 2.
Inside the Response and Request objects located in Zend\Http namespace we have 
an URI object and a protected variable called $queryParams. The protected 
variable holds que uri query parameters which may seem redundant as the URI 
also holds the query parameters as string. However they are NOT connected and 
could cause a bug.
Let's imagine in our code we get the Uri object and set some query parameters 
in it, for example:
$request->getUri()->setQuery("what=ever&we=want");
This will be ignored as the Request object is not aware of those changes.
After banging my head against the wall why not make the method getQuery from 
Zend\Uri\Uri return the Prameters object? This way the getQuery from the 
response could be a gateway/interface/alias to Uri::getQuery and this way any 
change made to the Uri object or to the Request/Response object would be 
identical avoiding this kind of conflicts.
The problem here is that currently there could be projects using the 
Uri::getQuery() method expecting a string and I'm not sure if the magic method 
__toString() from Parameters would do the trick. Maybe making uglier code like 
adding getQueryParams() to the Uri object?
Best regards                                      

Reply via email to