3v4l.org

run code in 300+ PHP versions simultaneously
<?php // The JSON extension wasn't bundled with PHP until version 5.2.0 if (version_compare(PHP_VERSION, '5.1.6', '<=')) exit('PHP version not supported: json_decode() not available'); // Stop 3v4l.org from showing parse errors in old PHP versions without support for classes or interfaces else {$_ = __COMPILER_HALT_OFFSET__; eval(substr(file_get_contents(__FILE__), $_ + 2));} __halt_compiler();?> // Polyfill JsonSerializable if (!interface_exists('JsonSerializable', FALSE)) { interface JsonSerializable { public function jsonSerialize(); } function json_serialize(JsonSerializable $object) { return json_encode($object->jsonSerialize()); } } interface JsonUnserializable extends JsonSerializable { public function jsonUnserialize($json); } class User implements JsonUnserializable { private $_name; public function __construct($name = NULL) { $this->setName($name); } public function setName($name) { $this->_name = $name; } public function getName() { return $this->_name; } public function jsonSerialize() { return array('name' => $this->getName()); } public function jsonUnserialize($json) { $this->setName($json->name); } } function json_unserialize($json, $className) { if (version_compare(PHP_VERSION, '5.3.9', '>=')) { $isUnserializable = is_a($className, 'JsonUnserializable', TRUE); } else { $isUnserializable = new $className instanceof JsonUnserializable; } if ($isUnserializable) { $object = new $className; $object->jsonUnserialize(json_decode($json)); return $object; } else { return FALSE; } } if (version_compare(PHP_VERSION, '5.4.0', '>=')) { assert(json_encode(new User('Bar')) === '{"name":"Bar"}'); } else { assert(json_serialize(new User('Bar')) === '{"name":"Bar"}'); } $user = json_unserialize('{"name":"Foo"}', 'User'); var_dump($user->getName());
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vvv2g
function name:  (null)
number of ops:  19
compiled vars:  !0 = $_
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'version_compare'
          1        SEND_VAL                                                 '8.0.0'
          2        SEND_VAL                                                 '5.1.6'
          3        SEND_VAL                                                 '%3C%3D'
          4        DO_ICALL                                         $1      
          5      > JMPZ                                                     $1, ->8
          6    > > EXIT                                                     'PHP+version+not+supported%3A+json_decode%28%29+not+available'
          7*       JMP                                                      ->18
    7     8    >   ASSIGN                                                   !0, 399
          9        INIT_FCALL                                               'substr'
         10        INIT_FCALL                                               'file_get_contents'
         11        SEND_VAL                                                 '%2Fin%2Fvvv2g'
         12        DO_ICALL                                         $3      
         13        SEND_VAR                                                 $3
         14        ADD                                              ~4      !0, 2
         15        SEND_VAL                                                 ~4
         16        DO_ICALL                                         $5      
         17        INCLUDE_OR_EVAL                                          $5, EVAL
         18      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.86 ms | 1395 KiB | 19 Q