From: mikko dot rantalainen at peda dot net
Operating system: Ubuntu Linux 18.04 64 bit
PHP version: 7.4.6
Package: *General Issues
Bug Type: Bug
Bug description:wrong parameters to callback set via assert_options(ASSERT_CALLBACK, ...)
Description:
------------
---
From manual page: https://php.net/function.assert-options
---
The documentation says that the signature of callback should be
assert_callback(string $file, int $line, string $assertion, string
$description)
However, the $assertion will be passed an empty string unless the
deprecated syntax is used for the actual assert(). The actual assertion
should be always passed as the 3rd parameter.
Note that if first parameter to assert() is a string, the string will be
passed as 3rd parameter to the handler. If first parameter is not a
string and second parameter is not set, the assert code will be passed
as 4th parameter to the handler. If first parameter passed to assert()
is not a string and second parameter is a string, the actual assert code
will be lost and the string given as the second parameter will be passed
as the 4th parameter to the handler.
The behavior seems to have been the same since version 5.4.8. Version
5.4.7 or any older didn't support the second parameter to assert().
The only way to get the expected output with current PHP version is to
use deprecated syntax assert(string, string) where both 3rd and 4th
parameter passed to assert handler will be correctly set.
I think the behavior of PHP should be changed instead of simply changing
the documentation. It really makes zero sense to always pass empty
string as the 3rd argument if non-deprecated features are used. (And
yeah, I see that sniper@php.net considered this feature-not-a-bug in
2002 - perhaps it's time to reconsider now that the string as the first
argument to assert() has been deprecated:
https://bugs.php.net/bug.php?id=20075)
Example test also at https://3v4l.org/1G2Zo
Test script:
---------------
<?php
assert_options(ASSERT_CALLBACK, "assert_handler");
function assert_handler($file, $line, $assertion, $description="")
{
echo "* assert_handler('$file', '$line', '$assertion',
'$description')
called";
return true;
}
assert('false == true');
assert(false == true);
assert(false == true, "Expected assert() to fail for this test and emit
the actual test as 3rd parameter to handler");
Expected result:
----------------
* assert_handler('/in/1G2Zo', '10', 'false == true', '')
called
* assert_handler('/in/1G2Zo', '11', 'false == true', '')
called
* assert_handler('/in/1G2Zo', '12', 'false == true', 'Expected
assert()
to fail for this test and emit the actual test as 3rd parameter to
handler') called
Actual result:
--------------
* assert_handler('/in/1G2Zo', '10', 'false == true', '')
called
* assert_handler('/in/1G2Zo', '11', '', 'assert(false ==
true)') called
* assert_handler('/in/1G2Zo', '12', '', 'Expected assert() to
fail for
this test and emit the actual test as 3rd parameter to handler') called
--
Edit bug report at https://bugs.php.net/bug.php?id=79602&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79602&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79602&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79602&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79602&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79602&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79602&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79602&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79602&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79602&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79602&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79602&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79602&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79602&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79602&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79602&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79602&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79602&r=mysqlcfg