Skip to content

Commit e349913

Browse files
committed
Fix delayed early binding class redeclaration error
If we bind the class to the runtime slot even if we're not the ones who have performed early binding we'll miss the redeclaration error in the ZEND_DECLARE_CLASS_DELAYED handler. Closes GH-11226
1 parent 0a04c00 commit e349913

5 files changed

+21
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ PHP NEWS
2424
- Opcache:
2525
. Fixed bug GH-11134 (Incorrect match default branch optimization). (ilutov)
2626
. Fixed too wide OR and AND range inference. (nielsdos)
27+
. Fixed missing class redeclaration error with OPcache enabled. (ilutov)
2728

2829
- PCNTL:
2930
. Fixed maximum argument count of pcntl_forkx(). (nielsdos)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
class Bar extends Foo {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
class Bar extends Foo {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Delayed early binding throws class redeclaration error
3+
--EXTENSIONS--
4+
opcache
5+
--FILE--
6+
<?php
7+
class Foo {}
8+
include __DIR__ . '/delayed_early_binding_redeclaration-1.inc';
9+
include __DIR__ . '/delayed_early_binding_redeclaration-2.inc';
10+
var_dump(class_exists(Bar::class));
11+
?>
12+
--EXPECTF--
13+
Fatal error: Cannot declare class Bar, because the name is already in use in %sdelayed_early_binding_redeclaration-2.inc on line %d

ext/opcache/zend_accelerator_util_funcs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ static void zend_accel_do_delayed_early_binding(
358358
ce = zend_try_early_bind(orig_ce, parent_ce, early_binding->lcname, zv);
359359
}
360360
}
361-
}
362-
if (ce && early_binding->cache_slot != (uint32_t) -1) {
363-
*(void**)((char*)run_time_cache + early_binding->cache_slot) = ce;
361+
if (ce && early_binding->cache_slot != (uint32_t) -1) {
362+
*(void**)((char*)run_time_cache + early_binding->cache_slot) = ce;
363+
}
364364
}
365365
}
366366
CG(compiled_filename) = orig_compiled_filename;

0 commit comments

Comments
 (0)