Skip to content

Default assert.exception to 1 #5925

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 1 commit into from
Aug 3, 2020
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
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ PHP 8.0 UPGRADE NOTES
========================================

- Core:
. Assertion failures now throw by default. If the old behavior is desired,
then set `assert.exception=0` in INI settings.
. Methods with the same name as the class are no longer interpreted as
constructors. The __construct() method should be used instead.
. Removed ability to call non-static methods statically.
Expand Down
3 changes: 3 additions & 0 deletions Zend/tests/arrow_functions/007.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
--TEST--
Pretty printing for arrow functions
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php

Expand Down
1 change: 1 addition & 0 deletions Zend/tests/ast/zend-pow-assign.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ZEND_POW_ASSIGN
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php

Expand Down
1 change: 1 addition & 0 deletions Zend/tests/ast_serialize_backtick_literal.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Serialization of backtick literal is incorrect
--INI--
zend.assertions=1
assert.exception=0
--FILE--
<?php

Expand Down
4 changes: 4 additions & 0 deletions Zend/tests/attributes/012_ast_export.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
--TEST--
Attributes AST can be exported.
--INI--
zend.assertions=1
assert.exception=0
assert.warning=1
--FILE--
<?php

Expand Down
2 changes: 2 additions & 0 deletions Zend/tests/match/009.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Pretty printing for match expression
--INI--
assert.exception=0
--FILE--
<?php

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("assert.bail", "0", PHP_INI_ALL, OnUpdateBool, bail, zend_assert_globals, assert_globals)
STD_PHP_INI_BOOLEAN("assert.warning", "1", PHP_INI_ALL, OnUpdateBool, warning, zend_assert_globals, assert_globals)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also set warning=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think not. Exception takes priority over warning, so it doesn't issue a warning and then throw; it only throws. This way reverting to PHP < 8 behavior is only assert.exception=0.

Copy link
Member

Choose a reason for hiding this comment

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

It seems pretty odd from a documentation perspective to have assert.warning=1 without actually enabling warnings. Ideally this would have been assert.mode=exception or so, because really only one of assert.bail, assert.exception and assert.warning makes sense at a time. But given things as they are, I would set it to zero.

PHP_INI_ENTRY("assert.callback", NULL, PHP_INI_ALL, OnChangeCallback)
STD_PHP_INI_BOOLEAN("assert.exception", "0", PHP_INI_ALL, OnUpdateBool, exception, zend_assert_globals, assert_globals)
STD_PHP_INI_BOOLEAN("assert.exception", "1", PHP_INI_ALL, OnUpdateBool, exception, zend_assert_globals, assert_globals)
PHP_INI_END()

static void php_assert_init_globals(zend_assert_globals *assert_globals_p) /* {{{ */
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 0
assert.warning = 1
assert.callback =
assert.bail = 0
assert.exception=0
--FILE--
<?php
function a($file, $line, $unused, $desc)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert03.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 0
assert.callback =
assert.bail = 0
assert.exception=0
--FILE--
<?php
function a($file, $line, $unused, $desc)
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert04.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 1
assert.callback =
assert.bail = 0
assert.exception=0
--FILE--
<?php
/* Assert not active */
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 0
assert.callback = f1
assert.bail = 0
assert.exception=0
--FILE--
<?php
function f1()
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_basic2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 1
assert.callback=f1
assert.bail = 0
assert.exception=0
--FILE--
<?php
function f2()
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_basic3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 1
assert.callback = f1
assert.bail = 0
assert.exception=0
--FILE--
<?php
function f1()
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_basic5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 0
assert.callback = f1
assert.bail = 0
assert.exception=0
--FILE--
<?php
function f1()
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_closures.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ assert() - basic - accept closures as callback.
assert.active = 1
assert.warning = 1
assert.bail = 0
assert.exception=0
--FILE--
<?php
assert_options(ASSERT_CALLBACK, function () { echo "Hello World!\n"; });
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_error2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 1
assert.callback = f1
assert.bail = 0
assert.exception=0
error_reporting = -1
display_errors = 1
--FILE--
Expand Down
1 change: 1 addition & 0 deletions ext/standard/tests/assert/assert_variation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ assert.active = 1
assert.warning = 0
assert.callback = f1
assert.bail = 0
assert.exception=0
--FILE--
<?php
function f1()
Expand Down