php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80221 Object-oriented interface for HashContext
Submitted: 2020-10-12 10:02 UTC Modified: 2020-10-12 11:01 UTC
From: divinity76 at gmail dot com Assigned:
Status: Suspended Package: hash related
PHP Version: Next Minor Version OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: divinity76 at gmail dot com
New email:
PHP Version: OS:

 

 [2020-10-12 10:02 UTC] divinity76 at gmail dot com
Description:
------------
the current HashContext only has a procedural interface, 
some people would prefer having an Object-oriented interface instead. (the same way mysqli_query() & co has both a procedural and object-oriented api)

for example, the current way to hash $str1 and $str2 is:

$hc = hash_init("SHA1");
hash_update($hc, $str1);
hash_update($hc, $str2);
$result = hash_final($hc);

(i've omitted error-checking for brevity)
but if we had an OO interface, it could also be written as: 

$result = (new HashContext("SHA1"))->update($str1)->update($str2)->final();

some people would prefer that. something like this: https://3v4l.org/lXd3u


Test script:
---------------
<?php
$str1 = "foo";
$str2 = "bar";
$result = (new HashContext("SHA1"))->update($str1)->update($str2)->final();
echo $result;

Expected result:
----------------
8843d7f92416211de9ebb963ff4ce28125932878


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-12 11:01 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2020-10-12 11:01 UTC] cmb@php.net
That makes sense, but the details need to be discussed (and the
feature may require an RFC[1]), and this bug tracker isn't really
suitable for that kind of discussion.  Therefore please forward
that request to the internals mailing list[2].  For the time
being, I'm suspending this ticket.

[1] <https://wiki.php.net/rfc/howto>
[2] <https://www.php.net/mailing-lists.php#internals>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC