diff --git a/NEWS b/NEWS index ebb93b6489c54..737e352b2d6e6 100644 --- a/NEWS +++ b/NEWS @@ -37,6 +37,8 @@ PHP NEWS - Standard: . Fixed bug GH-17403 (Potential deadlock when putenv fails). (nielsdos) . Fixed bug GH-18400 (http_build_query type error is inaccurate). (nielsdos) + . Fixed bug GH-18509 (Dynamic calls to assert() ignore zend.assertions). + (timwolla) - Windows: . Fix leak+crash with sapi_windows_set_ctrl_handler(). (nielsdos) diff --git a/ext/standard/assert.c b/ext/standard/assert.c index f0b6adadbe17d..258447576e1f4 100644 --- a/ext/standard/assert.c +++ b/ext/standard/assert.c @@ -178,7 +178,11 @@ PHP_FUNCTION(assert) zend_string *description_str = NULL; zend_object *description_obj = NULL; - if (!ASSERTG(active)) { + /* EG(assertions) <= 0 is only reachable by dynamic calls to assert(), + * since calls known at compile time will skip the entire call when + * assertions are disabled. + */ + if (!ASSERTG(active) || EG(assertions) <= 0) { RETURN_TRUE; } diff --git a/ext/standard/tests/assert/gh18509.phpt b/ext/standard/tests/assert/gh18509.phpt new file mode 100644 index 0000000000000..2bf1a04c87c69 --- /dev/null +++ b/ext/standard/tests/assert/gh18509.phpt @@ -0,0 +1,23 @@ +--TEST-- +GH-18509: Dynamic calls to assert() ignore zend.assertions +--INI-- +zend.assertions=0 +--FILE-- + +--EXPECT-- +array(3) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(true) +}