Skip to content

hash: Add simple HashContext::__debugInfo() implementation #14644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ PHP NEWS

- Hash:
. Changed return type of hash_update() to true. (nielsdos)
. Added HashContext::__debugInfo(). (timwolla)

- IMAP:
. Moved to PECL. (Derick Rethans)
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ PHP 8.4 UPGRADE NOTES
- FPM:
. Flushing headers without a body will now succeed. See GH-12785.

- Hash:
. Added HashContext::__debugInfo().

- Intl:
. NumberFormatter::ROUND_HALFODD added to complement existing
NumberFormatter::ROUND_HALFEVEN functionality.
Expand Down
15 changes: 15 additions & 0 deletions ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,21 @@ PHP_METHOD(HashContext, __unserialize)
}
/* }}} */

ZEND_METHOD(HashContext, __debugInfo)
{
zval *object = ZEND_THIS;
php_hashcontext_object *hash = php_hashcontext_from_object(Z_OBJ_P(object));

ZEND_PARSE_PARAMETERS_NONE();

zval tmp;

array_init(return_value);

ZVAL_STRING(&tmp, hash->ops->algo);
zend_hash_str_update(Z_ARR_P(return_value), "algo", strlen("algo"), &tmp);
}

/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(hash)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/hash/hash.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,6 @@ private function __construct() {}
public function __serialize(): array {}

public function __unserialize(array $data): void {}

public function __debugInfo(): array {}
}
6 changes: 5 additions & 1 deletion ext/hash/hash_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ext/hash/tests/HashContext_debugInfo.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Hash: HashContext::__debugInfo()
--FILE--
<?php

var_dump(hash_init('sha256'));
var_dump(hash_init('sha3-512'));

?>
--EXPECTF--
object(HashContext)#%d (1) {
["algo"]=>
string(6) "sha256"
}
object(HashContext)#%d (1) {
["algo"]=>
string(8) "sha3-512"
}
Loading