Skip to content

RFC: Deprecate remains of string evaluated code assertions #11671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ PHP 8.3 UPGRADE NOTES
. The MT_RAND_PHP Mt19937 variant is deprecated.
RFC: https://wiki.php.net/rfc/deprecations_php_8_3#mt_rand_php

- Standard:
. The assert_option() function is now deprecated.
Copy link
Contributor

@andypost andypost Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be assert_options()

. The ASSERT_ACTIVE, ASSERT_BAIL,ASSERT_CALLBACK, ASSERT_EXCEPTION, and
ASSERT_WARNING constants have been deprecated.
RFC: https://wiki.php.net/rfc/assert-string-eval-cleanup

- SQLite3
. Using exceptions is now preferred, warnings will be removed in the future.
Calling SQLite3::enableExceptions(false) will trigger a depreciation warning
Expand Down Expand Up @@ -355,6 +361,18 @@ PHP 8.3 UPGRADE NOTES
11. Changes to INI File Handling
========================================

- assert.*
. The assert.* INI settings have been deprecated.
This comprises the following INI settings:
- assert.active
- assert.bail
- assert.callback
- assert.exception
- assert.warning
If the value of the setting is equal to the default value, no deprecation
notice is emitted.
The zend.assertions INI setting should be used instead.

- zend.max_allowed_stack_size
. New INI directive to set the maximum allowed stack size. Possible
values are `0` (detect the process or thread maximum stack size), `-1`
Expand Down
22 changes: 15 additions & 7 deletions Zend/tests/arrow_functions/007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
Pretty printing for arrow functions
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php

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

?>
--EXPECTF--
Warning: assert(): assert(fn() => false()) failed in %s on line %d
try {
assert((fn() => false)());
} catch (AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}

try {
assert((fn&(int... $args): ?bool => $args[0])(false));
} catch (AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}

Warning: assert(): assert(fn&(int ...$args): ?bool => $args[0](false)) failed in %s on line %d
?>
--EXPECT--
assert(): assert(fn() => false()) failed
assert(): assert(fn&(int ...$args): ?bool => $args[0](false)) failed
30 changes: 19 additions & 11 deletions Zend/tests/assert/bug70528.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@
Bug #70528 (assert() with instanceof adds apostrophes around class name)
--INI--
zend.assertions=1
assert.exception=0
assert.warning=1
--FILE--
<?php

namespace Foo;
class Bar {}

$bar = "Bar";
assert(new \stdClass instanceof $bar);
assert(new \stdClass instanceof Bar);
assert(new \stdClass instanceof \Foo\Bar);
try {
assert(new \stdClass instanceof $bar);
} catch (\AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
try {
assert(new \stdClass instanceof Bar);
} catch (\AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
try {
assert(new \stdClass instanceof \Foo\Bar);
} catch (\AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
?>
--EXPECTF--
Warning: assert(): assert(new \stdClass() instanceof $bar) failed in %sbug70528.php on line %d

Warning: assert(): assert(new \stdClass() instanceof Bar) failed in %sbug70528.php on line %d

Warning: assert(): assert(new \stdClass() instanceof \Foo\Bar) failed in %sbug70528.php on line %d
--EXPECT--
assert(): assert(new \stdClass() instanceof $bar) failed
assert(): assert(new \stdClass() instanceof Bar) failed
assert(): assert(new \stdClass() instanceof \Foo\Bar) failed
56 changes: 37 additions & 19 deletions Zend/tests/assert/expect_015.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
AST pretty-peinter
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php
try {
assert(0 && ($a = function () {
global $a, $$b;
static $c, $d = 0;
Expand All @@ -19,7 +19,11 @@ assert(0 && ($a = function () {
yield 1 => 2;
yield from $x;
}));
} catch (AssertionError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
abstract class A extends B implements C, D {
const X = 12;
Expand Down Expand Up @@ -64,7 +68,11 @@ assert(0 && ($a = function &(array &$a, ?X $b = null) use ($c,&$d) : ?X {
}
}
}));
} catch (AssertionError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use ($c,&$d) : X {
final class A {
final protected function f2() {
Expand Down Expand Up @@ -96,7 +104,11 @@ L0:
}
}
}));
} catch (AssertionError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(0 && ($a = function &(?array &$a, X $b = null) use ($c,&$d) : X {
class A {
use T1, T2 {
Expand All @@ -108,7 +120,11 @@ assert(0 && ($a = function &(?array &$a, X $b = null) use ($c,&$d) : X {
use T3;
}
}));
} catch (AssertionError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(0 && ($a = function &(array &...$a) {
declare(A=1,B=2);
try {
Expand All @@ -121,7 +137,11 @@ assert(0 && ($a = function &(array &...$a) {
echo 3;
}
}));
} catch (AssertionError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(0 && ($a = function (): ?static {
declare(C=1) { echo 1; }
$x = '\'"`$a';
Expand All @@ -145,10 +165,13 @@ assert(0 && ($a = function (): ?static {
}
if ($a); else;
}));
} catch (AssertionError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECTF--
Warning: assert(): assert(0 && ($a = function () {
--EXPECT--
assert(0 && ($a = function () {
global $a;
global $$b;
static $c;
Expand All @@ -163,9 +186,8 @@ Warning: assert(): assert(0 && ($a = function () {
$y = clone $x;
yield 1 => 2;
yield from $x;
})) failed in %s on line %d

Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
}))
assert(0 && ($a = function &(array &$a, ?X $b = null) use($c, &$d): ?X {
abstract class A extends B implements C, D {
public const X = 12;
public const Y = self::X, Z = 'aaa';
Expand Down Expand Up @@ -208,9 +230,8 @@ Warning: assert(): assert(0 && ($a = function &(array &$a, ?X $b = null) use($c,

}

})) failed in %s on line %d

Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use($c, &$d): X {
}))
assert(0 && ($a = function &(array &$a, X $b = null, int|float $c) use($c, &$d): X {
final class A {
protected final function f2() {
if (!$x) {
Expand Down Expand Up @@ -248,9 +269,8 @@ Warning: assert(): assert(0 && ($a = function &(array &$a, X $b = null, int|floa

}

})) failed in %s on line %d

Warning: assert(): assert(0 && ($a = function &(?array &$a, X $b = null) use($c, &$d): X {
}))
assert(0 && ($a = function &(?array &$a, X $b = null) use($c, &$d): X {
class A {
use T1, T2 {
T1::foo insteadof foo;
Expand All @@ -261,9 +281,8 @@ Warning: assert(): assert(0 && ($a = function &(?array &$a, X $b = null) use($c,
use T3;
}

})) failed in %s on line %d

Warning: assert(): assert(0 && ($a = function &(array &...$a) {
}))
assert(0 && ($a = function &(array &...$a) {
declare(A = 1, B = 2);
try {
$i++;
Expand All @@ -274,9 +293,8 @@ Warning: assert(): assert(0 && ($a = function &(array &...$a) {
} finally {
echo 3;
}
})) failed in %s on line %d

Warning: assert(): assert(0 && ($a = function (): ?static {
}))
assert(0 && ($a = function (): ?static {
declare(C = 1) {
echo 1;
}
Expand All @@ -302,4 +320,4 @@ Warning: assert(): assert(0 && ($a = function (): ?static {
if ($a) {
} else {
}
})) failed in %s on line %d
}))
13 changes: 7 additions & 6 deletions Zend/tests/assert/expect_016.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@
test enable/disable assertions at runtime (assertions not completely disabled)
--INI--
zend.assertions=0
assert.exception=0
--FILE--
<?php
ini_set("zend.assertions", 0);
var_dump(assert(false));
var_dump(assert(true));
ini_set("zend.assertions", 1);
var_dump(assert(false));
try {
var_dump(assert(false));
} catch (AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
var_dump(assert(true));
ini_set("zend.assertions", -1);
?>
--EXPECTF--
bool(true)
bool(true)

Warning: assert(): assert(false) failed in %sexpect_016.php on line 6
bool(false)
assert(): assert(false) failed
bool(true)

Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_016.php on line 8
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %s on line %d
6 changes: 2 additions & 4 deletions Zend/tests/assert/expect_017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
test enable/disable assertions at runtime (assertions completely disabled)
--INI--
zend.assertions=-1
assert.exception=0
--FILE--
<?php
ini_set("zend.assertions", 0);
var_dump(assert(false));
var_dump(assert(true));
ini_set("zend.assertions", 0);
ini_set("zend.assertions", 1);
?>
--EXPECTF--
Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 2
bool(true)
bool(true)

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

Warning: zend.assertions may be completely enabled or disabled only in php.ini in %sexpect_017.php on line 5
23 changes: 13 additions & 10 deletions Zend/tests/assert/expect_018.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
test assertions in namespace
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php
namespace Foo;
Expand All @@ -13,21 +12,25 @@ var_dump(\assert(true));
var_dump(assert(false));
var_dump(assert(true));
ini_set("zend.assertions", 1);
var_dump(\assert(false));
try {
var_dump(\assert(false));
} catch (\AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
var_dump(\assert(true));
var_dump(assert(false));
try {
var_dump(assert(false));
} catch (\AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
var_dump(assert(true));
?>
--EXPECTF--
--EXPECT--
bool(true)
bool(true)
bool(true)
bool(true)

Warning: assert(): assert(false) failed in %sexpect_018.php on line 10
bool(false)
assert(): assert(false) failed
bool(true)

Warning: assert(): assert(false) failed in %sexpect_018.php on line 12
bool(false)
assert(): assert(false) failed
bool(true)
1 change: 0 additions & 1 deletion Zend/tests/assert/expect_019.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
test assertions in namespace (assertions completely disabled)
--INI--
zend.assertions=-1
assert.exception=0
--FILE--
<?php
namespace Foo;
Expand Down
11 changes: 7 additions & 4 deletions Zend/tests/assert/expect_020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
AST pretty-printer
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php
try {
assert(0 && ($a = function () {
$var = 'test';
$str = "$var, $var[1], {$var}[], {$var[1]}[], ${var}[], ${var[1]}[]";
}));
} catch (AssertionError $e) {
echo 'assert(): ', $e->getMessage(), ' failed', PHP_EOL;
}
?>
--EXPECTF--
Warning: assert(): assert(0 && ($a = function () {
--EXPECT--
assert(): assert(0 && ($a = function () {
$var = 'test';
$str = "$var, {$var[1]}, {$var}[], {$var[1]}[], {$var}[], {$var[1]}[]";
})) failed in %sexpect_020.php on line %d
})) failed
Loading