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

0 commit comments

Comments
 (0)