Skip to content

Commit eeb2e8e

Browse files
committed
Prevent early-binding
1 parent 64ab502 commit eeb2e8e

16 files changed

+90
-56
lines changed

Zend/tests/array_unpack/classes.phpt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ class C {
99
public static $bar = [...self::ARR];
1010
}
1111

12-
class D {
13-
public const A = [...self::B];
14-
public const B = [...self::A];
12+
try {
13+
class D {
14+
public const A = [...self::B];
15+
public const B = [...self::A];
16+
}
17+
} catch (Error $e) {
18+
echo $e->getMessage(), "\n";
1519
}
1620

1721
var_dump(C::FOO);
1822
var_dump(C::$bar);
1923

20-
try {
21-
var_dump(D::A);
22-
} catch (Error $ex) {
23-
echo "Exception: " . $ex->getMessage() . "\n";
24-
}
2524
?>
2625
--EXPECT--
26+
Cannot declare self-referencing constant self::B
2727
array(5) {
2828
[0]=>
2929
int(0)
@@ -44,4 +44,3 @@ array(3) {
4444
[2]=>
4545
int(3)
4646
}
47-
Exception: Cannot declare self-referencing constant self::B

Zend/tests/bug41633_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ echo Foo::A."\n";
1111
Fatal error: Uncaught Error: Undefined constant self::B in %s:%d
1212
Stack trace:
1313
#0 {main}
14-
thrown in %sbug41633_2.php on line 5
14+
thrown in %sbug41633_2.php on line 2

Zend/tests/bug69832.phpt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@ Bug #69832 (Assertion failed in zend_compile_const_expr_magic_const)
33
--FILE--
44
<?php
55

6+
if (true) {
7+
class Bar {
8+
const A = 1;
9+
}
10+
}
11+
612
class Test {
713
public $foo = [Bar::A, __CLASS__][__CLASS__ != ""];
814
public $bar = Bar::A && __CLASS__;
915
public $baz = Bar::A ?: __CLASS__;
1016
public $buzz = Bar::A ? __CLASS__ : 0;
1117
}
1218

13-
eval(<<<'PHP'
14-
class Bar {
15-
const A = 1;
16-
}
17-
PHP
18-
);
19-
2019
$t = new Test;
2120
var_dump($t->foo);
2221
var_dump($t->bar);

Zend/tests/bug78868.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
Bug #78868: Calling __autoload() with incorrect EG(fake_scope) value
33
--FILE--
44
<?php
5+
6+
function main_autoload($class_name) {
7+
$c = new C;
8+
$c->foo();
9+
//doesn't affect the error
10+
eval("class B {const foo = 1;}");
11+
}
12+
spl_autoload_register('main_autoload');
13+
514
class C {
615
private $private = 1;
716

@@ -14,15 +23,6 @@ class A {
1423
static $foo = B::foo; //not resolved on include()
1524
}
1625

17-
function main_autoload($class_name) {
18-
$c = new C;
19-
$c->foo();
20-
//doesn't affect the error
21-
eval("class B {const foo = 1;}");
22-
}
23-
24-
spl_autoload_register('main_autoload');
25-
2626
$classA = new ReflectionClass("A");
2727
$props = $classA->getProperties();
2828
$props[0]->setValue(2); //causes constant resolving, which runs autoload, all with EG(fake_scope) == "A"

Zend/tests/constexpr/objects.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ var_dump(test());
2727

2828
?>
2929
--EXPECT--
30-
object(Foo)#2 (1) {
30+
object(Foo)#1 (1) {
3131
["prop"]=>
3232
int(0)
3333
}
34-
object(Foo)#3 (1) {
34+
object(Foo)#2 (1) {
3535
["prop"]=>
3636
int(1)
3737
}
3838
object(Foo)#5 (1) {
3939
["prop"]=>
4040
int(2)
4141
}
42-
object(Foo)#1 (1) {
42+
object(Foo)#3 (1) {
4343
["prop"]=>
4444
int(3)
4545
}

Zend/tests/invalid_parent_const_ref_leak.phpt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ Leak when using an invalid parent:: reference in a constant definition
33
--FILE--
44
<?php
55

6-
class A {
7-
const B = parent::C;
8-
}
9-
106
try {
11-
A::B;
7+
class A {
8+
const B = parent::C;
9+
}
1210
} catch (Error $e) {
1311
echo $e->getMessage(), "\n";
1412
}

Zend/tests/type_declarations/typed_properties_021.phpt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
Test typed properties delay type check on constant
33
--FILE--
44
<?php
5-
class Foo {
6-
public int $bar = BAR::BAZ;
7-
}
8-
95
try {
10-
$foo = new Foo();
6+
class Foo {
7+
public int $bar = BAR::BAZ;
8+
}
119
} catch (Error $e) {
1210
echo $e->getMessage(), "\n";
1311
}

Zend/tests/type_declarations/typed_properties_058.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ class A {
1010
public int $foo = FOO;
1111
}
1212

13-
class B {
14-
public string $foo = FOO;
13+
try {
14+
class B {
15+
public string $foo = FOO;
16+
}
17+
} catch (TypeError $e) {
18+
echo $e->getMessage() . "\n";
1519
}
1620

1721
$o = new A();
@@ -27,6 +31,7 @@ for ($i = 0; $i < 2; $i++) {
2731
}
2832
?>
2933
--EXPECT--
34+
Cannot assign int to property B::$foo of type string
3035
int(5)
3136
Cannot assign int to property B::$foo of type string
3237
Cannot assign int to property B::$foo of type string

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7563,7 +7563,7 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{
75637563
}
75647564

75657565
/* We currently don't early-bind classes that implement interfaces or use traits */
7566-
if (!ce->num_interfaces && !ce->num_traits
7566+
if (!ce->num_interfaces && !ce->num_traits && (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)
75677567
&& !(CG(compiler_options) & ZEND_COMPILE_WITHOUT_EXECUTION)) {
75687568
if (toplevel) {
75697569
if (extends_ast) {

ext/reflection/tests/ReflectionClassConstant_toString_error.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ Exception thrown while converting ReflectionClassConstant to string
33
--FILE--
44
<?php
55

6-
class B {
7-
const X = self::UNKNOWN;
6+
try {
7+
class B {
8+
const X = self::UNKNOWN;
9+
}
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
812
}
913

1014
try {
@@ -16,3 +20,4 @@ try {
1620
?>
1721
--EXPECT--
1822
Undefined constant self::UNKNOWN
23+
Undefined constant self::UNKNOWN

ext/reflection/tests/ReflectionClass_toString_004.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ Constant evaluation exception during ReflectionClass::__toString()
33
--FILE--
44
<?php
55

6-
class A {
7-
const C = self::UNKNOWN;
6+
try {
7+
class A {
8+
const C = self::UNKNOWN;
9+
}
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
812
}
13+
914
try {
1015
echo new ReflectionClass(A::class);
1116
} catch (Error $e) {
@@ -15,3 +20,4 @@ try {
1520
?>
1621
--EXPECT--
1722
Undefined constant self::UNKNOWN
23+
Undefined constant self::UNKNOWN

ext/reflection/tests/bug76536.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
Bug #76536 (PHP crashes with core dump when throwing exception in error handler)
33
--FILE--
44
<?php
5-
class SomeConstants {const SOME_CONSTANT = "0foo" % 5; }
65

76
function handleError() {throw new ErrorException();}
87

98
set_error_handler('handleError');
109
set_exception_handler('handleError');
1110

11+
class SomeConstants {const SOME_CONSTANT = "0foo" % 5; }
12+
1213
$r = new \ReflectionClass(SomeConstants::class);
1314
$r->getConstants();
1415
?>

ext/standard/tests/filters/object_init_failure.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
Creating the stream filter object may fail
33
--FILE--
44
<?php
5-
class SampleFilter extends php_user_filter {
6-
private $data = \FOO;
5+
try {
6+
class SampleFilter extends php_user_filter {
7+
private $data = \FOO;
8+
}
9+
} catch (Error $e) {
10+
echo $e->getMessage(), "\n";
711
}
812
stream_filter_register('sample.filter', SampleFilter::class);
913
try {
@@ -13,6 +17,8 @@ try {
1317
}
1418
?>
1519
--EXPECTF--
20+
Undefined constant "FOO"
21+
1622
Warning: file_get_contents(): Unable to create or locate filter "sample.filter" in %s on line %d
1723

1824
Warning: file_get_contents(): Unable to create filter (sample.filter) in %s on line %d

ext/standard/tests/filters/object_init_failure_2.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
Creating the stream filter object may fail (include variation)
33
--FILE--
44
<?php
5-
class SampleFilter extends php_user_filter {
6-
private $data = \FOO;
5+
try {
6+
class SampleFilter extends php_user_filter {
7+
private $data = \FOO;
8+
}
9+
} catch (Error $e) {
10+
echo $e->getMessage(), "\n";
711
}
812
stream_filter_register('sample.filter', SampleFilter::class);
913
try {
@@ -13,6 +17,8 @@ try {
1317
}
1418
?>
1519
--EXPECTF--
20+
Undefined constant "FOO"
21+
1622
Warning: main(): Unable to create or locate filter "sample.filter" in %s on line %d
1723

1824
Warning: main(): Unable to create filter (sample.filter) in %s on line %d

ext/standard/tests/streams/bug77664.phpt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
BUG #77664 (Segmentation fault when using undefined constant in custom wrapper)
33
--FILE--
44
<?php
5-
class ErrorWrapper {
6-
public $context;
7-
public $var = self::INVALID;
5+
try {
6+
class ErrorWrapper {
7+
public $context;
8+
public $var = self::INVALID;
9+
}
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
812
}
913
stream_wrapper_register('error',ErrorWrapper::class);
1014
file_get_contents('error://test');
1115
?>
1216
--EXPECTF--
17+
Undefined constant self::INVALID
18+
1319
Fatal error: Uncaught Error: Undefined constant self::INVALID in %s:%d
1420
Stack trace:
1521
#0 %sbug77664.php(%d): file_get_contents('error://test')

ext/tokenizer/tests/PhpToken_extension_errors.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ PhpToken extensions that throw during construction
55
--FILE--
66
<?php
77

8-
class MyPhpToken1 extends PhpToken {
9-
public $extra = UNKNOWN;
8+
try {
9+
class MyPhpToken1 extends PhpToken {
10+
public $extra = UNKNOWN;
11+
}
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
1014
}
1115

1216
try {
@@ -27,4 +31,5 @@ try {
2731
?>
2832
--EXPECT--
2933
Undefined constant "UNKNOWN"
34+
Undefined constant "UNKNOWN"
3035
Cannot instantiate abstract class MyPhpToken2

0 commit comments

Comments
 (0)