Skip to content

Deprecate constant redeclaration #19474

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ PHP NEWS
triggers "Constant already defined" warning). (ilutov)
. Fixed bug GH-19476 (pipe operator fails to correctly handle returning
by reference). (alexandre-daubois)
. Constant redeclaration is deprecated and this behavior will trigger an
error in PHP 9. (alexandre-daubois)

- ODBC:
. Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley)
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ PHP 8.5 UPGRADE NOTES
. Returning null from __debugInfo() has been deprecated.
Return an empty array instead.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_debuginfo_returning_null
. Constant redeclaration is deprecated and that behavior will trigger an
error in PHP 9.
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_constant_redeclaration

- Curl:
. The curl_close() function has been deprecated, as CurlHandle objects are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var_dump($reflection->getAttributes())

?>
--EXPECTF--
Warning: Constant MY_CONST already defined in %s on line %d
Warning: Constant MY_CONST already defined, this will be an error in PHP 9 in %s on line %d
No attributes
array(0) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var_dump($reflection->getAttributes())

?>
--EXPECTF--
Warning: Constant MY_CONST already defined in %s on line %d
Warning: Constant MY_CONST already defined, this will be an error in PHP 9 in %s on line %d
Has attributes (1)
array(1) {
[0]=>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var_dump($reflection->getAttributes())

?>
--EXPECTF--
Warning: Constant MY_CONST already defined in %s on line %d
Warning: Constant MY_CONST already defined, this will be an error in PHP 9 in %s on line %d
Has attributes
array(1) {
[0]=>
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug29890.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ define("TEST",3);

?>
--EXPECT--
error :Constant TEST already defined
error :Constant TEST already defined, this will be an error in PHP 9
4 changes: 2 additions & 2 deletions Zend/tests/constants/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ echo "Done\n";
--EXPECTF--
TypeError: define(): Argument #1 ($constant_name) must be of type string, array given

Warning: Constant TRUE already defined in %s on line %d
Warning: Constant TRUE already defined, this will be an error in PHP 9 in %s on line %d
bool(false)
bool(true)
bool(true)
bool(true)

Warning: Constant test const already defined in %s on line %d
Warning: Constant test const already defined, this will be an error in PHP 9 in %s on line %d
bool(false)
bool(true)
bool(true)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/constants/constants_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var_dump(constant('1foo'));

?>
--EXPECTF--
Warning: Constant 1 already defined in %s on line %d
Warning: Constant 1 already defined, this will be an error in PHP 9 in %s on line %d
int(2)
int(2)
int(2)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/constants/constants_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const foo = 2;

?>
--EXPECTF--
Warning: Constant foo\foo already defined in %s on line %d
Warning: Constant foo\foo already defined, this will be an error in PHP 9 in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/constants/constants_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ if (defined('a')) {

?>
--EXPECTF--
Warning: Constant a already defined in %s on line %d
Warning: Constant a already defined, this will be an error in PHP 9 in %s on line %d
2
2 changes: 1 addition & 1 deletion Zend/tests/constants/halt_compiler/bug53305.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ var_dump(constant('__COMPILER_HALT_OFFSET__1'.chr(0)));

?>
--EXPECTF--
Warning: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d
Warning: Constant __COMPILER_HALT_OFFSET__ already defined, this will be an error in PHP 9 in %s on line %d
int(1)
int(4)
2 changes: 1 addition & 1 deletion Zend/tests/constants/halt_compiler/halt_compiler3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ __HALT_COMPILER(); bad define() of __COMPILER_HALT_OFFSET__ 1
define ('__COMPILER_HALT_OFFSET__', 1);
?>
--EXPECTF--
Warning: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d
Warning: Constant __COMPILER_HALT_OFFSET__ already defined, this will be an error in PHP 9 in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/constants/halt_compiler/halt_compiler4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ __HALT_COMPILER();
?>
==DONE==
--EXPECTF--
Warning: Constant __COMPILER_HALT_OFFSET__ already defined in %s on line %d
Warning: Constant __COMPILER_HALT_OFFSET__ already defined, this will be an error in PHP 9 in %s on line %d
2 changes: 1 addition & 1 deletion Zend/zend_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ ZEND_API zend_constant *zend_register_constant(zend_constant *c)
|| (!persistent && zend_get_special_const(ZSTR_VAL(name), ZSTR_LEN(name)))
|| (ret = zend_hash_add_constant(EG(zend_constants), name, c)) == NULL
) {
zend_error(E_WARNING, "Constant %s already defined", ZSTR_VAL(name));
zend_error(E_WARNING, "Constant %s already defined, this will be an error in PHP 9", ZSTR_VAL(name));
zend_string_release(c->name);
if (c->filename) {
zend_string_release(c->filename);
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/tests/bug71127.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ include($file);
@unlink(__DIR__ . "/bug71127.inc");
?>
--EXPECTF--
Warning: Constant FOO already defined in %sbug71127.inc on line %d
Warning: Constant FOO already defined, this will be an error in PHP 9 in %sbug71127.inc on line %d
okey