Search code examples
phpjsonangularjszend-frameworkmamp

JSON-String in PHP Array index 0


Hello i have a problem since my Mamp Pro upgrade an the new PHP 5.3.29 Version on my MacOS Dev-System.

I use AngularJS in the Browser and send my Form-Data with PUT/POST-Request to the Server.

POST-Request:

{"checklistentyp":"SB Rollout","anzahl_filialen":"12","kam":"1","kb":"1"}

On Server-Side i use PHP 5.3.29 width ZendFramework 1.12.8 and RESTful When i dump the Request-Data:var_dump($this->_request->getParams());

I have my JSON-String in a Array on index 0

array(5) {
 ["module"]=> string(3) "api"
 ["controller"]=> string(10) "checkliste"
 ["action"]=> string(4) "post"
 ["format"]=>string(4) "json"
 [0]=>string(73) "{"checklistentyp":"SB Rollout","anzahl_filialen":"12","kam":"1","kb":"1"}"
}

My Prodserver with Linux and PHP 5.3.10 don't have this Problem and all works.

Before the Upgrade to an new MAMP-Version all works fine on my MacOS Dev-System.

Update: With PHP 5.3.14 the same Problem. I use for RESTful this Library https://github.com/codeinchaos/restful-zend-framework

Update 2: I think i found the problem. When i do this:

$fc = Zend_Controller_Front::getInstance();
$cp = $fc->getRequest()->getHeader('Content-Type');
var_dump($cp);

The dump output is bool(false)

So i think the Problem is between Zend and PHP. The context-Switcher in the RESTful library can't detect the Content-Typ and return the raw body. Any Idea to fix this problem?


Solution

  • There is a PHP bug in Mac OSX which is currently open. See https://bugs.php.net/bug.php?id=66606&thanks=6

    Zend Framework, in certain environments is affected, because the bug prevents the header type to being determined properly. restful-zend-framework depends on $fc->getRequest()->getHeader('Content-Type') method to determine response. See http://framework.zend.com/issues/browse/ZF-5705. This document includes a work-around.

    Adding the following code to public/index.php should fix.

    if (isset($_SERVER['CONTENT_TYPE'])
       && !isset($_SERVER['HTTP_CONTENT_TYPE'])
    ) {
       $_SERVER['HTTP_CONTENT_TYPE'] = $_SERVER['CONTENT_TYPE'];
    }