<?php
class Foo implements \JsonSerializable
{
protected $bar;
protected $foobar;
public $mybar;
public function getBar()
{
return $this->bar;
}
public function jsonSerialize()
{
return ['mybar'=>'foo'];
}
}
var_dump(json_encode(new Foo));
Deprecated: Return type of Foo::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/ri6Wq on line 14
string(15) "{"mybar":"foo"}"
Parse error: syntax error, unexpected '[' in /in/ri6Wq on line 16
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ri6Wq on line 3
Parse error: syntax error, unexpected '[' in /in/ri6Wq on line 16
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ri6Wq on line 3
Parse error: parse error, unexpected '[' in /in/ri6Wq on line 16
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/ri6Wq on line 3
Process exited with code 255.