Skip to content

Commit ac54d1c

Browse files
authored
hash: Add simple HashContext::__debugInfo() implementation (#14644)
* hash: Add simply HashContext::__debugInfo() implementation * NEWS/UPGRADING
1 parent 5b1b3ae commit ac54d1c

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ PHP NEWS
8383

8484
- Hash:
8585
. Changed return type of hash_update() to true. (nielsdos)
86+
. Added HashContext::__debugInfo(). (timwolla)
8687

8788
- IMAP:
8889
. Moved to PECL. (Derick Rethans)

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ PHP 8.4 UPGRADE NOTES
230230
- FPM:
231231
. Flushing headers without a body will now succeed. See GH-12785.
232232

233+
- Hash:
234+
. Added HashContext::__debugInfo().
235+
233236
- Intl:
234237
. NumberFormatter::ROUND_HALFODD added to complement existing
235238
NumberFormatter::ROUND_HALFEVEN functionality.

ext/hash/hash.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,21 @@ PHP_METHOD(HashContext, __unserialize)
15601560
}
15611561
/* }}} */
15621562

1563+
ZEND_METHOD(HashContext, __debugInfo)
1564+
{
1565+
zval *object = ZEND_THIS;
1566+
php_hashcontext_object *hash = php_hashcontext_from_object(Z_OBJ_P(object));
1567+
1568+
ZEND_PARSE_PARAMETERS_NONE();
1569+
1570+
zval tmp;
1571+
1572+
array_init(return_value);
1573+
1574+
ZVAL_STRING(&tmp, hash->ops->algo);
1575+
zend_hash_str_update(Z_ARR_P(return_value), "algo", strlen("algo"), &tmp);
1576+
}
1577+
15631578
/* {{{ PHP_MINIT_FUNCTION */
15641579
PHP_MINIT_FUNCTION(hash)
15651580
{

ext/hash/hash.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,6 @@ private function __construct() {}
102102
public function __serialize(): array {}
103103

104104
public function __unserialize(array $data): void {}
105+
106+
public function __debugInfo(): array {}
105107
}

ext/hash/hash_arginfo.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Hash: HashContext::__debugInfo()
3+
--FILE--
4+
<?php
5+
6+
var_dump(hash_init('sha256'));
7+
var_dump(hash_init('sha3-512'));
8+
9+
?>
10+
--EXPECTF--
11+
object(HashContext)#%d (1) {
12+
["algo"]=>
13+
string(6) "sha256"
14+
}
15+
object(HashContext)#%d (1) {
16+
["algo"]=>
17+
string(8) "sha3-512"
18+
}

0 commit comments

Comments
 (0)