3v4l.org

run code in 300+ PHP versions simultaneously
<?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());
Output for git.master, git.master_jit, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
34.4 ms | 401 KiB | 8 Q