3v4l.org

run code in 300+ PHP versions simultaneously
<?php // i wish the php builtin HashContext class had this stuff: class OOHashContext{ private $hc; public const HASH_HMAC=1; public function __construct(string $algo, int $options = 0, string $key = NULL){ if(!($this->hc = hash_init($algo, $options, $key))){ throw new \RuntimeException(); } } public function update(string $data):self{ if(!hash_update($this->hc, $data)){ throw new \RuntimeException(); } return $this; } public function update_file(string $file, $scontext = null):self{ if(!hash_update_file($this->hc, $file, $scontext)){ throw new \RuntimeException(); } return $this; } public function update_stream($handle, int $length = -1):self{ if(!hash_update_stream($this->hc, $handle, $length)){ throw new \RuntimeException(); } return $this; } public function final(bool $raw_output = false):string{ $ret = hash_final($this->hc, $raw_output); if(!is_string($ret)){ throw new \RuntimeException(); } return $ret; } } $o=new OOHashContext("SHA1"); $str1="foo"; $str2="bar"; $result = (new OOHashContext("SHA1"))->update($str1)->update($str2)->final(); echo $result;
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: hash_init(): Passing null to parameter #3 ($key) of type string is deprecated in /in/lXd3u on line 7 Deprecated: hash_init(): Passing null to parameter #3 ($key) of type string is deprecated in /in/lXd3u on line 7 8843d7f92416211de9ebb963ff4ce28125932878

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:
138.92 ms | 406 KiB | 5 Q