Skip to content

Commit 3d4ff5a

Browse files
authored
RFC: Deprecate remains of string evaluated code assertions (#11671)
Link: https://wiki.php.net/rfc/assert-string-eval-cleanup
1 parent 591f3f6 commit 3d4ff5a

40 files changed

+497
-187
lines changed

UPGRADING

+18
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ PHP 8.3 UPGRADE NOTES
126126
. The MT_RAND_PHP Mt19937 variant is deprecated.
127127
RFC: https://wiki.php.net/rfc/deprecations_php_8_3#mt_rand_php
128128

129+
- Standard:
130+
. The assert_option() function is now deprecated.
131+
. The ASSERT_ACTIVE, ASSERT_BAIL,ASSERT_CALLBACK, ASSERT_EXCEPTION, and
132+
ASSERT_WARNING constants have been deprecated.
133+
RFC: https://wiki.php.net/rfc/assert-string-eval-cleanup
134+
129135
- SQLite3
130136
. Using exceptions is now preferred, warnings will be removed in the future.
131137
Calling SQLite3::enableExceptions(false) will trigger a depreciation warning
@@ -364,6 +370,18 @@ PHP 8.3 UPGRADE NOTES
364370
11. Changes to INI File Handling
365371
========================================
366372

373+
- assert.*
374+
. The assert.* INI settings have been deprecated.
375+
This comprises the following INI settings:
376+
- assert.active
377+
- assert.bail
378+
- assert.callback
379+
- assert.exception
380+
- assert.warning
381+
If the value of the setting is equal to the default value, no deprecation
382+
notice is emitted.
383+
The zend.assertions INI setting should be used instead.
384+
367385
- zend.max_allowed_stack_size
368386
. New INI directive to set the maximum allowed stack size. Possible
369387
values are `0` (detect the process or thread maximum stack size), `-1`

Zend/tests/arrow_functions/007.phpt

+15-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22
Pretty printing for arrow functions
33
--INI--
44
zend.assertions=1
5-
assert.exception=0
65
--FILE--
76
<?php
87

98
// TODO We're missing parentheses for the direct call
10-
assert((fn() => false)());
11-
assert((fn&(int... $args): ?bool => $args[0])(false));
129

13-
?>
14-
--EXPECTF--
15-
Warning: assert(): assert(fn() => false()) failed in %s on line %d
10+
try {
11+
assert((fn() => false)());
12+
} catch (AssertionError $e) {
13+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
14+
}
15+
16+
try {
17+
assert((fn&(int... $args): ?bool => $args[0])(false));
18+
} catch (AssertionError $e) {
19+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
20+
}
1621

17-
Warning: assert(): assert(fn&(int ...$args): ?bool => $args[0](false)) failed in %s on line %d
22+
?>
23+
--EXPECT--
24+
assert(): assert(fn() => false()) failed
25+
assert(): assert(fn&(int ...$args): ?bool => $args[0](false)) failed

Zend/tests/assert/bug70528.phpt

+19-11
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,30 @@
22
Bug #70528 (assert() with instanceof adds apostrophes around class name)
33
--INI--
44
zend.assertions=1
5-
assert.exception=0
6-
assert.warning=1
75
--FILE--
86
<?php
97

108
namespace Foo;
119
class Bar {}
1210

1311
$bar = "Bar";
14-
assert(new \stdClass instanceof $bar);
15-
assert(new \stdClass instanceof Bar);
16-
assert(new \stdClass instanceof \Foo\Bar);
12+
try {
13+
assert(new \stdClass instanceof $bar);
14+
} catch (\AssertionError $e) {
15+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
16+
}
17+
try {
18+
assert(new \stdClass instanceof Bar);
19+
} catch (\AssertionError $e) {
20+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
21+
}
22+
try {
23+
assert(new \stdClass instanceof \Foo\Bar);
24+
} catch (\AssertionError $e) {
25+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
26+
}
1727
?>
18-
--EXPECTF--
19-
Warning: assert(): assert(new \stdClass() instanceof $bar) failed in %sbug70528.php on line %d
20-
21-
Warning: assert(): assert(new \stdClass() instanceof Bar) failed in %sbug70528.php on line %d
22-
23-
Warning: assert(): assert(new \stdClass() instanceof \Foo\Bar) failed in %sbug70528.php on line %d
28+
--EXPECT--
29+
assert(): assert(new \stdClass() instanceof $bar) failed
30+
assert(): assert(new \stdClass() instanceof Bar) failed
31+
assert(): assert(new \stdClass() instanceof \Foo\Bar) failed

Zend/tests/assert/expect_015.phpt

+37-19
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
AST pretty-peinter
33
--INI--
44
zend.assertions=1
5-
assert.exception=0
65
--FILE--
76
<?php
7+
try {
88
assert(0 && ($a = function () {
99
global $a, $$b;
1010
static $c, $d = 0;
@@ -19,7 +19,11 @@ assert(0 && ($a = function () {
1919
yield 1 => 2;
2020
yield from $x;
2121
}));
22+
} catch (AssertionError $e) {
23+
echo $e->getMessage(), PHP_EOL;
24+
}
2225

26+
try {
2327
assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
2428
abstract class A extends B implements C, D {
2529
const X = 12;
@@ -64,7 +68,11 @@ assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
6468
}
6569
}
6670
}));
71+
} catch (AssertionError $e) {
72+
echo $e->getMessage(), PHP_EOL;
73+
}
6774

75+
try {
6876
assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use ($c,&$d) : X {
6977
final class A {
7078
final protected function f2() {
@@ -96,7 +104,11 @@ L0:
96104
}
97105
}
98106
}));
107+
} catch (AssertionError $e) {
108+
echo $e->getMessage(), PHP_EOL;
109+
}
99110

111+
try {
100112
assert(0 && ($a = function &(?array &$a, X $b = null) use ($c,&$d) : X {
101113
class A {
102114
use T1, T2 {
@@ -108,7 +120,11 @@ assert(0 && ($a = function &(?array &$a, X $b = null) use ($c,&$d) : X {
108120
use T3;
109121
}
110122
}));
123+
} catch (AssertionError $e) {
124+
echo $e->getMessage(), PHP_EOL;
125+
}
111126

127+
try {
112128
assert(0 && ($a = function &(array &...$a) {
113129
declare(A=1,B=2);
114130
try {
@@ -121,7 +137,11 @@ assert(0 && ($a = function &(array &...$a) {
121137
echo 3;
122138
}
123139
}));
140+
} catch (AssertionError $e) {
141+
echo $e->getMessage(), PHP_EOL;
142+
}
124143

144+
try {
125145
assert(0 && ($a = function (): ?static {
126146
declare(C=1) { echo 1; }
127147
$x = '\'"`$a';
@@ -145,10 +165,13 @@ assert(0 && ($a = function (): ?static {
145165
}
146166
if ($a); else;
147167
}));
168+
} catch (AssertionError $e) {
169+
echo $e->getMessage(), PHP_EOL;
170+
}
148171

149172
?>
150-
--EXPECTF--
151-
Warning: assert(): assert(0 && ($a = function () {
173+
--EXPECT--
174+
assert(0 && ($a = function () {
152175
global $a;
153176
global $$b;
154177
static $c;
@@ -163,9 +186,8 @@ Warning: assert(): assert(0 && ($a = function () {
163186
$y = clone $x;
164187
yield 1 => 2;
165188
yield from $x;
166-
})) failed in %s on line %d
167-
168-
Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
189+
}))
190+
assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
169191
abstract class A extends B implements C, D {
170192
public const X = 12;
171193
public const Y = self::X, Z = 'aaa';
@@ -208,9 +230,8 @@ Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c,
208230

209231
}
210232

211-
})) failed in %s on line %d
212-
213-
Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use($c, &$d): X {
233+
}))
234+
assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use($c, &$d): X {
214235
final class A {
215236
protected final function f2() {
216237
if (!$x) {
@@ -248,9 +269,8 @@ Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null, int|floa
248269

249270
}
250271

251-
})) failed in %s on line %d
252-
253-
Warning: assert(): assert(0 && ($a = function &(?array &$a, X $b = null) use($c, &$d): X {
272+
}))
273+
assert(0 && ($a = function &(?array &$a, X $b = null) use($c, &$d): X {
254274
class A {
255275
use T1, T2 {
256276
T1::foo insteadof foo;
@@ -261,9 +281,8 @@ Warning: assert(): assert(0 && ($a = function &(?array &$a, X $b = null) use($c,
261281
use T3;
262282
}
263283

264-
})) failed in %s on line %d
265-
266-
Warning: assert(): assert(0 && ($a = function &(array &...$a) {
284+
}))
285+
assert(0 && ($a = function &(array &...$a) {
267286
declare(A = 1, B = 2);
268287
try {
269288
$i++;
@@ -274,9 +293,8 @@ Warning: assert(): assert(0 && ($a = function &(array &...$a) {
274293
} finally {
275294
echo 3;
276295
}
277-
})) failed in %s on line %d
278-
279-
Warning: assert(): assert(0 && ($a = function (): ?static {
296+
}))
297+
assert(0 && ($a = function (): ?static {
280298
declare(C = 1) {
281299
echo 1;
282300
}
@@ -302,4 +320,4 @@ Warning: assert(): assert(0 && ($a = function (): ?static {
302320
if ($a) {
303321
} else {
304322
}
305-
})) failed in %s on line %d
323+
}))

Zend/tests/assert/expect_016.phpt

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22
test enable/disable assertions at runtime (assertions not completely disabled)
33
--INI--
44
zend.assertions=0
5-
assert.exception=0
65
--FILE--
76
<?php
87
ini_set("zend.assertions", 0);
98
var_dump(assert(false));
109
var_dump(assert(true));
1110
ini_set("zend.assertions", 1);
12-
var_dump(assert(false));
11+
try {
12+
var_dump(assert(false));
13+
} catch (AssertionError $e) {
14+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
15+
}
1316
var_dump(assert(true));
1417
ini_set("zend.assertions", -1);
1518
?>
1619
--EXPECTF--
1720
bool(true)
1821
bool(true)
19-
20-
Warning: assert(): assert(false) failed in %sexpect_016.php on line 6
21-
bool(false)
22+
assert(): assert(false) failed
2223
bool(true)
2324

24-
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_016.php on line 8
25+
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %s on line %d

Zend/tests/assert/expect_017.phpt

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
test enable/disable assertions at runtime (assertions completely disabled)
33
--INI--
44
zend.assertions=-1
5-
assert.exception=0
65
--FILE--
76
<?php
7+
ini_set("zend.assertions", 0);
88
var_dump(assert(false));
99
var_dump(assert(true));
10-
ini_set("zend.assertions", 0);
1110
ini_set("zend.assertions", 1);
1211
?>
1312
--EXPECTF--
13+
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 2
1414
bool(true)
1515
bool(true)
1616

17-
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 4
18-
1917
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 5

Zend/tests/assert/expect_018.phpt

+13-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
test assertions in namespace
33
--INI--
44
zend.assertions=1
5-
assert.exception=0
65
--FILE--
76
<?php
87
namespace Foo;
@@ -13,21 +12,25 @@ var_dump(\assert(true));
1312
var_dump(assert(false));
1413
var_dump(assert(true));
1514
ini_set("zend.assertions", 1);
16-
var_dump(\assert(false));
15+
try {
16+
var_dump(\assert(false));
17+
} catch (\AssertionError $e) {
18+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
19+
}
1720
var_dump(\assert(true));
18-
var_dump(assert(false));
21+
try {
22+
var_dump(assert(false));
23+
} catch (\AssertionError $e) {
24+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
25+
}
1926
var_dump(assert(true));
2027
?>
21-
--EXPECTF--
28+
--EXPECT--
2229
bool(true)
2330
bool(true)
2431
bool(true)
2532
bool(true)
26-
27-
Warning: assert(): assert(false) failed in %sexpect_018.php on line 10
28-
bool(false)
33+
assert(): assert(false) failed
2934
bool(true)
30-
31-
Warning: assert(): assert(false) failed in %sexpect_018.php on line 12
32-
bool(false)
35+
assert(): assert(false) failed
3336
bool(true)

Zend/tests/assert/expect_019.phpt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
test assertions in namespace (assertions completely disabled)
33
--INI--
44
zend.assertions=-1
5-
assert.exception=0
65
--FILE--
76
<?php
87
namespace Foo;

Zend/tests/assert/expect_020.phpt

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
AST pretty-printer
33
--INI--
44
zend.assertions=1
5-
assert.exception=0
65
--FILE--
76
<?php
7+
try {
88
assert(0 && ($a = function () {
99
$var = 'test';
1010
$str = "$var, $var[1], {$var}[], {$var[1]}[], ${var}[], ${var[1]}[]";
1111
}));
12+
} catch (AssertionError $e) {
13+
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
14+
}
1215
?>
13-
--EXPECTF--
14-
Warning: assert(): assert(0 && ($a = function () {
16+
--EXPECT--
17+
assert(): assert(0 && ($a = function () {
1518
$var = 'test';
1619
$str = "$var, {$var[1]}, {$var}[], {$var[1]}[], {$var}[], {$var[1]}[]";
17-
})) failed in %sexpect_020.php on line %d
20+
})) failed

0 commit comments

Comments
 (0)