3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Hash { protected $algo; private $bytes; protected $data; public function __construct(string $data) { $this->bytes = strlen(hash($this->algo, '', true)); $this->data = $data; } public function getRaw() : string { return $this->data; } public function getHex() : string { return bin2hex($this->data); } public function getBase64() : string { return base64_encode($this->data); } public static function fromHex(string $data) : Hash { return new static(hex2bin($data)); } public static function fromBase64(string $data) : Hash { return new static(base64_decode($data)); } public static function getClass(string $algo) : string { $prefix = ucfirst(strtolower($algo)); $class = implode('\\', [__NAMESPACE__, "${prefix}Hash"]); return $class; } } final class Md5Hash extends Hash { protected $algo = 'md5'; } final class Sha256Hash extends Hash { protected $algo = 'sha256'; } final class Sha512Hash extends Hash { protected $algo = 'sha512'; } foreach(explode('|', 'md5|sha256|sha512') as $a){ $submitted[$a] = hash($a, 'foobar'); } foreach($submitted as $algo => $hexVal){ $hashes[] = (Hash::getClass($algo))::fromHex($hexVal); } var_dump($hashes);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /in/bSBD0 on line 44 array(3) { [0]=> object(Md5Hash)#1 (3) { ["algo":protected]=> string(3) "md5" ["bytes":"Hash":private]=> int(16) ["data":protected]=> string(16) "8X�"0�<�_0 fC�?" } [1]=> object(Sha256Hash)#2 (3) { ["algo":protected]=> string(6) "sha256" ["bytes":"Hash":private]=> int(32) ["data":protected]=> string(32) "ë��7 譐G�9Fk<�t��8=J9`qL����" } [2]=> object(Sha512Hash)#3 (3) { ["algo":protected]=> string(6) "sha512" ["bytes":"Hash":private]=> int(64) ["data":protected]=> string(64) " P&�9�+�&�g<U��4-R2�=3�aj�i�X|�c_i%�l60��'5�>�$%" } }

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:
40.34 ms | 402 KiB | 8 Q