Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8d2682f

Browse files
standard: Take zend.assertions into account for dynamic calls to assert() (php#18521)
Fixes php#18509.
1 parent e7a44a6 commit 8d2682f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ PHP NEWS
3434

3535
- Standard:
3636
. Fixed bug GH-17403 (Potential deadlock when putenv fails). (nielsdos)
37+
. Fixed bug GH-18509 (Dynamic calls to assert() ignore zend.assertions).
38+
(timwolla)
3739

3840
- Windows:
3941
. Fix leak+crash with sapi_windows_set_ctrl_handler(). (nielsdos)

‎ext/standard/assert.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ PHP_FUNCTION(assert)
178178
zend_string *description_str = NULL;
179179
zend_object *description_obj = NULL;
180180

181-
if (!ASSERTG(active)) {
181+
/* EG(assertions) <= 0 is only reachable by dynamic calls to assert(),
182+
* since calls known at compile time will skip the entire call when
183+
* assertions are disabled.
184+
*/
185+
if (!ASSERTG(active) || EG(assertions) <= 0) {
182186
RETURN_TRUE;
183187
}
184188

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-18509: Dynamic calls to assert() ignore zend.assertions
3+
--INI--
4+
zend.assertions=0
5+
--FILE--
6+
<?php
7+
8+
$c = "assert";
9+
10+
$c(false);
11+
12+
var_dump(array_map(assert(...), [true, true, false]));
13+
14+
?>
15+
--EXPECT--
16+
array(3) {
17+
[0]=>
18+
bool(true)
19+
[1]=>
20+
bool(true)
21+
[2]=>
22+
bool(true)
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /