3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php namespace WoohooLabs\Yang\JsonApi\Request; use Psr\Http\Message\RequestInterface; class RequestBuilder { /** * @var \Psr\Http\Message\RequestInterface */ protected $request; /** * @var string */ protected $method; /** * @var array */ protected $queryString; /** * @param \Psr\Http\Message\RequestInterface $request */ public function __construct() { $this->initialize(); } public function initialize() { $this->method = "GET"; $this->queryString = []; } public function fetch() { $this->method = "GET"; } public function create() { $this->method = "POST"; } public function update() { $this->method = "PATCH"; } public function delete() { $this->method = "DELETE"; } /** * @param array|string $fields */ public function fields($fields) { $this->setQueryParam("fields", $fields); } /** * @param array|string $fields */ public function sort($fields) { $this->setQueryParam("sort", $fields); } /** * @param array|string $paginate */ public function paginate($paginate) { $this->setQueryParam("page", $paginate); } /** * @param array|string $filter */ public function filter($filter) { $this->setQueryParam("filter", $filter); } /** * @param array|string $includes */ public function includes($includes) { if (is_array($includes)) { $this->queryString["includes"] = implode(",", $includes); } else { $this->queryString["includes"] = $includes; } } /** * @return \Psr\Http\Message\RequestInterface */ public function getRequest() { $request = $this->request->withMethod($this->method); $request = $request->withUri($request->getUri()->withQuery($this->getQueryString())); return $request; } /** * @return string */ public function getQueryString() { return http_build_query($this->queryString); } /** * @param string $name * @param array|string $queryParam */ protected function setQueryParam($name, $queryParam) { if (is_array($queryParam)) { foreach ($queryParam as $key => $value) { $this->queryString[$name][$key] = $queryParam; } } else { $this->queryString[$name] = $queryParam; } } /** * @param array $array * @return bool */ protected function isAssociativeArray(array $array) { return (bool)count(array_filter(array_keys($array), 'is_string')); } } $builder = new RequestBuilder(); $builder->fields(["kaka" => "1,2,3,4", "shohoh" => "6,5,4,3"]); echo url_decode($builder->getQueryString());
based on as5Vh
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function WoohooLabs\Yang\JsonApi\Request\url_decode() in /in/K4ddW:148 Stack trace: #0 {main} thrown in /in/K4ddW on line 148
Process exited with code 255.
Output for 5.4.1 - 5.6.28
Fatal error: Call to undefined function WoohooLabs\Yang\JsonApi\Request\url_decode() in /in/K4ddW on line 148
Process exited with code 255.
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/K4ddW on line 34
Process exited with code 255.