4

I noticed a strange bug in my application that happens when using the AWS Elastic Beanstalk PHP 5.4.9 AMI.

When submitting a GET AJAX request that contains the header 'Content-Type: application/json' the $_POST superglobal is set to null. If I remove that header, it is set as expected to a blank array()

Is this expected behaviour?

greg
  • 6,853
  • 15
  • 58
  • 71
  • 2
    Nothing in the docs implies this is expected in PHP > 5.4. I'm not running PHP 5.4.9. However, if you can replicate this by doing the above, I'd submit a bug. – Jason McCreary Jan 07 '13 at 22:10
  • 2
    I remember one question on SO that was talking as well about `$_POST` being `NULL`. I don't know if that was related to AJAX or Json content-type request header. And I dunno if that was resolved anyway. I suggest you setup some test-case and outline here how this can be reproduced. BTW: If you do a GET request, there is no request body, so there is no `Content-Type` request header so it looks a bit bogus to have that at all. Sure this does not explain the `NULL` for `$_POST`, but one probably should not expect too much either. – hakre Jan 07 '13 at 22:25
  • Have you got a test case to demonstrate this? BTW, if you're doing a GET then $_POST shouldn't contain anything (though I believe it should always exist as an empty array) – GordonM Jan 07 '13 at 22:29
  • My JS framework (spine.js) always contains that header regardless of whether it is GET or POST. My Server side framework (Symfony2) expects $_POST to always be an array. It's never been a problem until AWS updated php to 5.4.9. I'll do some more testing and report back. – greg Jan 07 '13 at 22:40
  • Create simple page with ` – dev-null-dweller Jan 08 '13 at 00:41
  • What should the $_POST contain? The deserialized JSON data? It shouldn't be array() otherwise, because that is not what was POSTed. This seems to be by design. – oxygen Jan 08 '13 at 02:59
  • 1
    Looks as though PECL HTTP extension was causing the issue. – greg Jan 08 '13 at 18:09
  • Update: Fixed by the PHP team: https://bugs.php.net/bug.php?id=63947&edit=2 – greg Jan 09 '13 at 16:49

1 Answers1

2

Turns out this was an issue with PECL. When PECL HTTP is installed running PHP 5.4, it causes $_POST to be set to null when a "Content-Type: application/json" header is provided for a GET request. Removing PECL HTTP solves the problem.

Credit to Michael@AWS for the find. Cross thread: https://forums.aws.amazon.com/message.jspa?messageID=413836

Edit: Fixed by the PHP team: https://bugs.php.net/bug.php?id=63947&edit=2

greg
  • 6,853
  • 15
  • 58
  • 71