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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
5 + 44 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 21:01:31 2024 UTC