3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace wrossmann\merkle; class Node { public $value = NULL; public $isLeaf = false; public $height = 0; public $left = NULL; public $right = NULL; public $parent = NULL; } class Tree { protected $root = null; protected $nodes = []; public function serialize() { yield from $this->serializeGenerator($this->root); } // Serialize based on a depth-first traversal protected function serializeGenerator(Node $node) { yield [ 'v' => $node->value, 'l' => $node->isLeaf ]; if( ! is_null($node->left) ) { yield from $this->serializeGenerator($node->left); } if( ! is_null($node->right) ) { yield from $this->serializeGenerator($node->right); } } } // pre-constructed tree $m = unserialize(gzuncompress(base64_decode('eJy1VbtuwzAMzLdw7GTLz1K/UDhLxyxKIj9Qxy6kPoYg/17SXmIoKBBI2kj6rDvyaHmPIkX4NbO1FzVNh4s2H6M+vButAQVeLVYIu5edmecvkPvH6GY+E7pkdIHwo8ZvDdJijaCOp7Nuu57TEmGwb1q1II+YrIVeD11PBw9LIUcYdfs0T77yROUQzBGVgaDKIUj/JWjkcoRZHzYr9lMZPVFqME3k7R7wtB634QB6NqXSRyF5Etl1gp7CzkC8enriNhxAj+vJFuSjmZREvwEEc8TeBB128kXmuQluwwH0bEq517KSKZFtJ2gXdgiV16oT1G04gJ4Hprjf512l4bxe/tsTKbUgFaVXpqZbOCcNKb+VUiAoyDIKMj46oSDnXagoKPguYHDJQkoKKgpqWpPbH0CgjUU='))); printf("%s\n\n", json_encode(iterator_to_array($m->serialize(), false)));
Output for 7.1.0 - 7.1.24, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
[{"v":"abcdefgh","l":false},{"v":"abcd","l":false},{"v":"ab","l":false},{"v":"a","l":true},{"v":"b","l":true},{"v":"cd","l":false},{"v":"c","l":true},{"v":"d","l":true},{"v":"efgh","l":false},{"v":"ef","l":false},{"v":"e","l":true},{"v":"f","l":true},{"v":"gh","l":false},{"v":"g","l":true},{"v":"h","l":true}]
Output for 5.6.38
Parse error: syntax error, unexpected '$this' (T_VARIABLE) in /in/TQi2O on line 18
Process exited with code 255.

preferences:
28.65 ms | 460 KiB | 5 Q