Bug #81546 [Opn->Nab]: md2 parameter 2 expects bool but treats truthy as true
Edit report at https://bugs.php.net/bug.php?id=81546&edit=1
ID: 81546
Updated by: nikic@php.net
Reported by: devstemail at gmail dot com
Summary: md2 parameter 2 expects bool but treats truthy as
true
-Status: Open
+Status: Not a bug
Type: Bug
Package: hash related
Operating System: Centos 8
PHP Version: 8.1.0RC4
Block user comment: N
Private report: N
New Comment:
md5() uses standard bool parameter semantics. Use declare(strict_types=1) for strict type checks.
Previous Comments:
------------------------------------------------------------------------
[2021-10-20 10:22:21] devstemail at gmail dot com
Description:
------------
$binary treats truthy values (e.g. non-empty string) as true
```
$binary = 'hello';
echo md5( 'abc', $binary );
```
outputs a binary md5, instead of a hex md5, even though we didn't pass true
It should only output a binary md5 if $binary === true, not if $binary ==
true
As the documentation states:
>If the optional binary is set to **true**, then the md5 digest is instead returned in raw binary
>format with a length of 16.
# Solution
Basically what we need here is 2 things:
1) a notice, like we already have for the 1st arg:
md5() expects parameter 2 to be bool, string given
2) strict checking $binary === true, not $binary == true
Test script:
---------------
$binary = 'hello';
echo md5( 'abc', $binary );
Expected result:
----------------
1) a notice, like we already have for the 1st arg:
md5() expects parameter 2 to be bool, string given
2) strict checking $binary === true, not $binary == true
so we would get a hex md5 not a binary in this example
Actual result:
--------------
binary md5
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81546&edit=1
Thread (2 messages)