Skip to content

Commit b1b0c81

Browse files
committed
Don't print preload warning for non-top-level classes
Dynamically declared classes categorically do not get linked during preloading, even if all their dependencies are known. The warning is misleading in this case, and there isn't anything the user can do to address it.
1 parent b5746a4 commit b1b0c81

File tree

8 files changed

+3
-16
lines changed

8 files changed

+3
-16
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4034,7 +4034,8 @@ static void preload_link(void)
40344034
if (ce->type == ZEND_INTERNAL_CLASS) {
40354035
break;
40364036
}
4037-
if (!(ce->ce_flags & ZEND_ACC_LINKED)) {
4037+
if ((ce->ce_flags & (ZEND_ACC_TOP_LEVEL|ZEND_ACC_ANON_CLASS))
4038+
&& !(ce->ce_flags & ZEND_ACC_LINKED)) {
40384039
zend_string *key = zend_string_tolower(ce->name);
40394040
if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)
40404041
&& zend_hash_exists(EG(class_table), key)) {

ext/opcache/tests/bug78937_1.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class Bar {
1818
var_dump(foo());
1919
?>
2020
--EXPECTF--
21-
Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78937.inc on line 6
22-
2321
Warning: Can't preload unlinked class Bar@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2422
object(Bar@anonymous)#%d (0) {
2523
}

ext/opcache/tests/bug78937_2.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class Bar {
1919
var_dump(foo());
2020
?>
2121
--EXPECTF--
22-
Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78937.inc on line 6
23-
2422
Warning: Can't preload unlinked class Bar@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2523
object(Bar@anonymous)#%d (0) {
2624
}

ext/opcache/tests/bug78937_3.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ include(__DIR__ . "/preload_bug78937.inc");
1717
var_dump(foo());
1818
?>
1919
--EXPECTF--
20-
Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78937.inc on line 6
21-
2220
Warning: Can't preload unlinked class Bar@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2321

2422
Fatal error: Uncaught Error: Class "Bar" not found in %spreload_bug78937.inc:3

ext/opcache/tests/bug78937_4.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ bar();
1919
var_dump(new Foo);
2020
?>
2121
--EXPECTF--
22-
Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78937.inc on line 6
23-
2422
Warning: Can't preload unlinked class Bar@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2523
object(Foo)#%d (0) {
2624
}

ext/opcache/tests/bug78937_5.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ bar();
2020
var_dump(new Foo);
2121
?>
2222
--EXPECTF--
23-
Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78937.inc on line 6
24-
2523
Warning: Can't preload unlinked class Bar@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2624
object(Foo)#%d (0) {
2725
}

ext/opcache/tests/bug78937_6.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ bar();
1818
var_dump(new Foo);
1919
?>
2020
--EXPECTF--
21-
Warning: Can't preload unlinked class Foo: Unknown parent Bar in %spreload_bug78937.inc on line 6
22-
2321
Warning: Can't preload unlinked class Bar@anonymous: Unknown parent Bar in %spreload_bug78937.inc on line 3
2422

2523
Fatal error: Uncaught Error: Class "Bar" not found in %spreload_bug78937.inc:6

ext/opcache/tests/preload_enum.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ var_dump(MyEnum::Foo);
1717
var_dump(MyEnum::Bar);
1818

1919
?>
20-
--EXPECTF--
20+
--EXPECT--
2121
enum(MyEnum::Bar)
22-
23-
Warning: Can't preload unlinked class MyEnum2: Unknown reason in %s on line %d
2422
enum(MyEnum::Foo)
2523
enum(MyEnum::Bar)

0 commit comments

Comments
 (0)