php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81546 md2 parameter 2 expects bool but treats truthy as true
Submitted: 2021-10-20 10:22 UTC Modified: 2021-10-20 10:25 UTC
From: devstemail at gmail dot com Assigned:
Status: Not a bug Package: hash related
PHP Version: 8.1.0RC4 OS: Centos 8
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: devstemail at gmail dot com
New email:
PHP Version: OS:

 

 [2021-10-20 10:22 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-20 10:25 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-10-20 10:25 UTC] nikic@php.net
md5() uses standard bool parameter semantics. Use declare(strict_types=1) for strict type checks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 03:01:28 2024 UTC