3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ReportController { protected $source; protected $data; public function __construct(array $source, \Closure $transformer, $dataObject = null) { $this->source = $source; $this->data = ($dataObject) ? new stdClass() : $dataObject; $this->transform($transformer); } public function transform(\Closure $transformer) { array_walk($this->source, $transformer, "bob"); } public function getData() { return $this->data; } } $source = [ ['type'=>'open'], ['type'=>'closed'], ['type'=>'pending'], ['type'=>'accepted'] ]; $transformer = function($ticket, $key, $data) { var_dump($key, $data); (isset($data[$ticket['type']]))? $data[$ticket['type']]++: $data[$ticket['type']]=1; }; $report = new ReportController($source, $transformer); var_dump($report->getData());
Output for git.master, git.master_jit, rfc.property-hooks
int(0) string(3) "bob" Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /in/Efi29:35 Stack trace: #0 [internal function]: {closure}(Array, 0, 'bob') #1 /in/Efi29(18): array_walk(Array, Object(Closure), 'bob') #2 /in/Efi29(13): ReportController->transform(Object(Closure)) #3 /in/Efi29(38): ReportController->__construct(Array, Object(Closure)) #4 {main} thrown in /in/Efi29 on line 35
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:
58.15 ms | 402 KiB | 8 Q