1.2.50. Assert Function Is Reserved¶
Avoid defining an
assert
function in namespaces.
While they work fine when the assertions are active (zend.assertions=1
), calls to unqualified assert
are optimized away when assertions are not active.
Since PHP 7.3, a fatal error is emitted : Defining a custom `assert() <https://www.php.net/assert>`_ function is deprecated, as the function has special semantics
.
<?php
// Run this with zend.assertions=1 and
// Then run this with zend.assertions=0
namespace Test {
function assert() {
global $foo;
$foo = true;
}
}
namespace Test {
assert();
var_dump(isset($foo));
}
?>
See also assert and User-defined assert function is optimized away with zend.assertions=-1.
1.2.50.1. Suggestions¶
Rename the custom function with another name
1.2.50.2. Specs¶
Short name |
Php/AssertFunctionIsReserved |
Rulesets |
All, Analyze, Changed Behavior, CompatibilityPHP73, Deprecated |
Exakat since |
1.3.9 |
PHP Version |
All |
Severity |
Critical |
Time To Fix |
Slow (1 hour) |
Changed Behavior |
PHP 7.2 - More |
Precision |
Very high |
Features |
assertion |
Available in |