diff --git a/tests/ext/sandbox/install_hook/exclude_inherited_hook_after_binding.phpt b/tests/ext/sandbox/install_hook/exclude_inherited_hook_after_binding.phpt new file mode 100644 index 0000000000..8f3c8ed383 --- /dev/null +++ b/tests/ext/sandbox/install_hook/exclude_inherited_hook_after_binding.phpt @@ -0,0 +1,28 @@ +--TEST-- +remove_hook() with class argument +--FILE-- +foo(); // no hook + +?> +--EXPECT-- +GrandChild diff --git a/tests/ext/sandbox/install_hook/remove_hook_null_logger.phpt b/tests/ext/sandbox/install_hook/remove_hook_null_logger.phpt new file mode 100644 index 0000000000..7d56cd3d1b --- /dev/null +++ b/tests/ext/sandbox/install_hook/remove_hook_null_logger.phpt @@ -0,0 +1,43 @@ +--TEST-- +Remove hook +--ENV-- +DD_TRACE_LOGS_ENABLED=false +--FILE-- +log("info", "Hello World!"); + } +} + +?> +--EXPECTF-- +Psr\Log\NullLogger +Psr\Log\NullLogger +Psr\Log\NullLogger diff --git a/zend_abstract_interface/hook/hook.c b/zend_abstract_interface/hook/hook.c index 0b064cd6ea..eceda5ed46 100644 --- a/zend_abstract_interface/hook/hook.c +++ b/zend_abstract_interface/hook/hook.c @@ -936,6 +936,17 @@ zai_hook_continued zai_hook_continue(zend_execute_data *ex, zai_hook_memory_t *m } if (check_scope) { + if (zai_hook_is_excluded(hook, ex->func->common.scope)) { + // hook is no longer valid, remove it + zai_hook_remove_from_entry(hooks, hook->id); + + zend_hash_iterator_del(ht_iter); + memory->hook_count = (zend_ulong)hook_num; + zai_hook_finish(ex, NULL, memory); + + return ZAI_HOOK_BAILOUT; + } + if (!(hook->resolved_scope->ce_flags & ZEND_ACC_TRAIT) && !instanceof_function(zend_get_called_scope(ex), hook->resolved_scope)) { continue; }