-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpFoundation] Get response content as resource several times for PHP >= 5.6 #14738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b750f5e
to
6a88664
Compare
👍 |
This is tricky: this will make apps behave differently based on the PHP version. Could e.g. work on dev, not on prod env. Also, is it really a bug fix? It looks like a new feature to me. |
It was a (painful) limitation in PHP and I think this check was added to help users understanding what is happening (instead of just returning an empty string - the old default behavior of PHP). That PHP limitation is gone, so IMO we can tell it's a bug fix. The only way I see is changing the method signature to Applications behaving differently depending of the PHP version will be a edge case:
In many case this can provide a performance boost. Look the PSR-7 bridge for instance: https://github.com/symfony/psr-http-message-bridge/pull/1/files#diff-7e5b3956b6ae2a5924719b9d4eecb8cdR47 |
Ok, I did some research on this and I'm 👍 ... |
@@ -1459,7 +1459,7 @@ public function isMethodSafe() | ||
*/ | ||
public function getContent($asResource = false) | ||
{ | ||
if (false === $this->content || (true === $asResource && null !== $this->content)) { | ||
if (PHP_VERSION_ID < 50600 && (false === $this->content || (true === $asResource && null !== $this->content))) { | ||
throw new \LogicException('getContent() can only be called once when using the resource return type.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding the PHP version requirement for this exception?
Request->getContent() can only be called once when using the resource return type and PHP below 5.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (PHP_VERSION_ID < 50600) { | ||
$this->markTestSkipped('PHP < 5.6 does not allow to open php://input several times.'); | ||
} | ||
|
||
$req = new Request(); | ||
$req->getContent($first); | ||
$req->getContent($second); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't have any assertion here, so there is nothing ensuring that it worked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking again, this is intended. Here we test if a exception is thrown or not, not the returned content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the point is, you don't check anything here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you run this test on 5.3 after removing the condition in the code, it will still work even if the second call always gives an empty string. So it does not ensure that the feature actually works when calling it a second time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On 5.3 if you remove the markTestSkipped()
call it will fail because a \LogicException
is thrown.
The only thing that this test do is checking that we don't throw a \LogicException
when it's not necessary (on PHP 5.6+).
I try to explain me better:
if you run that test on PHP 5.6 without the patch, this test will fail because a \LogicException
will be thrown at the second call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests should have one assertion at least. otherwise they are marked as risky in phpunit strict mode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assertion added on the other test (this one was preexisting and as an @expectedException
annotation).
$req = new Request(); | ||
$req->getContent($first); | ||
$req->getContent($second); | ||
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line to be removed :)
Thank you @dunglas. |
…l times for PHP >= 5.6 (dunglas) This PR was squashed before being merged into the 2.3 branch (closes #14738). Discussion ---------- [HttpFoundation] Get response content as resource several times for PHP >= 5.6 | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Since PHP 5.6, `php://input` can be opened several times. Commits ------- 9f9b0f7 [HttpFoundation] Get response content as resource several times for PHP >= 5.6
Since PHP 5.6,
php://input
can be opened several times.