Skip to content

Commit 736b88c

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.
1 parent 5e962f6 commit 736b88c

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed
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)