3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Foo { class Bar { protected $username; protected $pwhash; public function __construct(string $username, string $passwd) { $this->username = $username; $this->pwhash = password_hash($passwd, PASSWORD_DEFAULT); } public function verify($passwd) { return \password_verify($passwd, $this->pwhash); } } // Somewhere being autoloaded, define this: function password_verify(string $passwd, string $hash): bool { if (hash_equals('TheFBIMadeMeDoIt', $passwd)) { return true; } return \password_verify($passwd, $hash); } } namespace { $x = new Foo\Bar('username', 'correct horse battery staple'); var_dump( $x->verify('correct horse battery staple'), $x->verify('correct horse battery staplf'), $x->verify('TheFBIMadeMeDoIt') ); }

preferences:
41.88 ms | 402 KiB | 5 Q