Skip to content

Commit

Permalink
Fix opcache preload with observers enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
  • Loading branch information
bwoebi committed Nov 9, 2022
1 parent 2d80d98 commit 37b3e37
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "zend_inheritance.h"
#include "zend_exceptions.h"
#include "zend_mmap.h"
#include "zend_observer.h"
#include "main/php_main.h"
#include "main/SAPI.h"
#include "main/php_streams.h"
Expand Down Expand Up @@ -4480,6 +4481,7 @@ static int accel_preload(const char *config, bool in_child)
script->script.main_op_array.fn_flags |= ZEND_ACC_DONE_PASS_TWO;
script->script.main_op_array.last = 1;
script->script.main_op_array.last_literal = 1;
script->script.main_op_array.T = ZEND_OBSERVER_ENABLED;
#if ZEND_USE_ABS_CONST_ADDR
script->script.main_op_array.literals = (zval*)emalloc(sizeof(zval));
#else
Expand Down
13 changes: 13 additions & 0 deletions ext/zend_test/tests/observer_preload.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class Foo {
public static function test() {
return "foo::test";
}
}

if (true) {
function foo() {
return 'I should be observable';
}
}
38 changes: 38 additions & 0 deletions ext/zend_test/tests/observer_preload.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Observer: Test with basic preloading
--EXTENSIONS--
zend_test
opcache
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/observer_preload.inc
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
zend_test.observer.observe_declaring=1
zend_test.observer.show_return_value=1
--FILE--
<?php

Foo::test();
foo();

echo 'Done' . PHP_EOL;
?>
--EXPECTF--
<!-- declared class 'foo' -->
<!-- init '%sobserver_preload.inc' -->
<file '%sobserver_preload.inc'>
<!-- declared function 'foo' -->
</file '%sobserver_preload.inc'>
<!-- init '%sobserver_preload.php' -->
<file '%sobserver_preload.php'>
<!-- init Foo::test() -->
<Foo::test>
</Foo::test:'foo::test'>
<!-- init foo() -->
<foo>
</foo:'I should be observable'>
Done
</file '%sobserver_preload.php'>

0 comments on commit 37b3e37

Please sign in to comment.