Skip to content

Commit aad3987

Browse files
committed
Remove bareword fallback for constants
Access to undefined constants will now always result in an Error exception being thrown. This required quite a few test changes, because there were many buggy tests that unintentionally used bareword fallback in combination with error suppression.
1 parent 3d39479 commit aad3987

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+372
-467
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ PHP 8.0 UPGRADE NOTES
2929
longer available. The error_get_last() function may be used instead.
3030
. Removed the ability to define case-insensitive constants. The third
3131
argument to define() may no longer be true.
32+
. Access to undefined constants now always results in an Error exception.
33+
Previously, unqualified constant accesses resulted in a warning and were
34+
interpreted as strings.
3235
. Removed ability to specify an autoloader using an __autoload() function.
3336
spl_autoload_register() should be used instead.
3437
. Removed create_function(). Anonymous functions may be used instead.

Zend/tests/bug37811.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ string(3) "Foo"
2323

2424
Warning: Constants may only evaluate to scalar values, arrays or resources in %sbug37811.php on line %d
2525

26-
Warning: Use of undefined constant Baz - assumed 'Baz' (this will throw an Error in a future version of PHP) in %sbug37811.php on line %d
27-
string(3) "Baz"
28-
===DONE===
26+
Fatal error: Uncaught Error: Undefined constant 'Baz' in %s:%d
27+
Stack trace:
28+
#0 {main}
29+
thrown in %s on line %d

Zend/tests/bug43344_1.phpt

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Bug #43344.1 (Wrong error message for undefined namespace constant)
33
--FILE--
44
<?php
55
namespace Foo;
6+
use Error;
7+
68
function f1($a=bar) {
79
return $a;
810
}
@@ -13,20 +15,31 @@ function f3($a=array(bar=>0)) {
1315
reset($a);
1416
return key($a);
1517
}
16-
echo bar."\n";
17-
echo f1()."\n";
18-
echo f2()."\n";
19-
echo f3()."\n";
20-
?>
21-
--EXPECTF--
22-
Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 13
23-
bar
2418

25-
Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 3
26-
bar
27-
28-
Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 6
29-
bar
19+
try {
20+
echo bar."\n";
21+
} catch (Error $e) {
22+
echo $e->getMessage(), "\n";
23+
}
24+
try {
25+
echo f1()."\n";
26+
} catch (Error $e) {
27+
echo $e->getMessage(), "\n";
28+
}
29+
try {
30+
echo f2()."\n";
31+
} catch (Error $e) {
32+
echo $e->getMessage(), "\n";
33+
}
34+
try {
35+
echo f3()."\n";
36+
} catch (Error $e) {
37+
echo $e->getMessage(), "\n";
38+
}
3039

31-
Warning: Use of undefined constant bar - assumed 'bar' (this will throw an Error in a future version of PHP) in %sbug43344_1.php on line 9
32-
bar
40+
?>
41+
--EXPECT--
42+
Undefined constant 'Foo\bar'
43+
Undefined constant 'Foo\bar'
44+
Undefined constant 'Foo\bar'
45+
Undefined constant 'Foo\bar'

Zend/tests/bug47572.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ $foo = new Foo();
1414

1515
?>
1616
--EXPECTF--
17-
Warning: Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in %s on line %d
17+
Fatal error: Uncaught Error: Undefined constant 'FOO' in %s:%d
18+
Stack trace:
19+
#0 {main}
20+
thrown in %s on line %d

Zend/tests/bug69755.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ Bug #69755: segfault in ZEND_CONCAT_SPEC_TMPVAR_CONST_HANDLER
55
c . 10;
66
?>
77
--EXPECTF--
8-
Warning: Use of undefined constant c - assumed 'c' (this will throw an Error in a future version of PHP) in %sbug69755.php on line 2
8+
Fatal error: Uncaught Error: Undefined constant 'c' in %s:%d
9+
Stack trace:
10+
#0 {main}
11+
thrown in %s on line %d

Zend/tests/bug69788.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ Bug #69788: Malformed script causes Uncaught Error in php-cgi, valgrind SIGILL
55
--EXPECTF--
66
Notice: Array to string conversion in %s on line %d
77

8-
Warning: Use of undefined constant t - assumed 't' (this will throw an Error in a future version of PHP) in %s on line %d
8+
Fatal error: Uncaught Error: Undefined constant 't' in %s:%d
9+
Stack trace:
10+
#0 {main}
11+
thrown in %s on line %d

Zend/tests/bug72944.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Bug #72944 (Null pointer deref in zval_delref_p).
33
--FILE--
44
<?php
5+
define('e', 'e');
56
"a"== e & $A = $A? 0 : 0 ?:0;
67
echo "OK\n";
78
?>
89
--EXPECTF--
9-
Warning: Use of undefined constant e - assumed 'e' (this will throw an Error in a future version of PHP) in %sbug72944.php on line 2
10-
11-
Notice: Undefined variable: A in %sbug72944.php on line 2
10+
Notice: Undefined variable: A in %sbug72944.php on line 3
1211
OK

Zend/tests/bug73163.phpt

Lines changed: 0 additions & 22 deletions
This file was deleted.

Zend/tests/constants_002.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ Defining constants with non-scalar values
44
<?php
55

66
define('foo', new stdClass);
7-
var_dump(foo);
7+
try {
8+
var_dump(foo);
9+
} catch (Error $e) {
10+
echo $e->getMessage(), "\n";
11+
}
812

913
define('foo', fopen(__FILE__, 'r'));
1014
var_dump(foo);
1115

1216
?>
1317
--EXPECTF--
1418
Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
15-
16-
Warning: Use of undefined constant foo - assumed 'foo' (this will throw an Error in a future version of PHP) in %s on line %d
17-
string(%d) "foo"
18-
resource(%d) of type (stream)
19+
Undefined constant 'foo'
20+
resource(5) of type (stream)

Zend/tests/constants_005.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
Persistent case insensitive and user defined constants
33
--FILE--
44
<?php
5-
var_dump(ZEND_THREAD_safe);
5+
var_dump(defined('ZEND_THREAD_safe'));
66
define("ZEND_THREAD_safe", 123);
77
var_dump(ZEND_THREAD_safe);
88
?>
9-
--EXPECTF--
10-
Warning: Use of undefined constant ZEND_THREAD_safe - assumed 'ZEND_THREAD_safe' (this will throw an Error in a future version of PHP) in %s on line %d
11-
string(16) "ZEND_THREAD_safe"
9+
--EXPECT--
10+
bool(false)
1211
int(123)

0 commit comments

Comments
 (0)