Permalink
Browse files

Remove special handling of empty arrays, fixes #5506

  • Loading branch information...
1 parent 6e49a86 commit fadbd3b3071d3306fb3c2cd9fd2daa10e65a6c5b @Seldaek Seldaek committed with fabpot Jan 9, 2013
Showing with 5 additions and 7 deletions.
  1. +5 −7 JsonResponse.php
View
@@ -28,17 +28,20 @@ class JsonResponse extends Response
* @param integer $status The response status code
* @param array $headers An array of response headers
*/
- public function __construct($data = array(), $status = 200, $headers = array())
+ public function __construct($data = null, $status = 200, $headers = array())
{
parent::__construct('', $status, $headers);
+ if (null === $data) {
+ $data = new \ArrayObject();
+ }
$this->setData($data);
}
/**
* {@inheritDoc}
*/
- public static function create($data = array(), $status = 200, $headers = array())
+ public static function create($data = null, $status = 200, $headers = array())
{
return new static($data, $status, $headers);
}
@@ -79,11 +82,6 @@ public function setCallback($callback = null)
*/
public function setData($data = array())
{
- // root should be JSON object, not array
- if (is_array($data) && 0 === count($data)) {
- $data = new \ArrayObject();
- }
-
// Encode <, >, ', &, and " for RFC4627-compliant JSON, which may also be embedded into HTML.
$this->data = json_encode($data, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT);

0 comments on commit fadbd3b

Please sign in to comment.