[php-src] PR #21470: Fix GH-18714: opcache_compile_file() breaks class hoisting

From: Date: Wed, 18 Mar 2026 21:34:33 +0000
Subject: [php-src] PR #21470: Fix GH-18714: opcache_compile_file() breaks class hoisting
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35266@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21470 Author: iliaal ## Summary opcache_compile_file() followed by require_once on the same file fails with "Class not found" when the class is used before its declaration (relying on class hoisting). Root cause: opcache_compile_file() sets ZEND_COMPILE_WITHOUT_EXECUTION which prevents simple parentless classes from being linked during compilation. The cached script stores the class as unlinked, and opcache's delayed early binding can't resolve it -- the class has no parent to look up but isn't marked as linked either, so the binding is silently skipped. **Fix (two parts):** - **Zend/zend_compile.c**: Separate the "link unbound simple class" path from the "early bind" path. Linking a parentless, trait-free, interface-free class is purely structural (zend_build_properties_info_table + zend_inheritance_check_override + ZEND_ACC_LINKED flag) with no execution side effects. Allow it even with ZEND_COMPILE_WITHOUT_EXECUTION, but not during preloading which has its own class linking pipeline. - **ext/opcache/zend_accelerator_module.c**: opcache_compile_file() goes through persistent_compile_file() which calls zend_accel_load_script(), registering classes/functions in the runtime tables. This is a side effect that causes duplicate registration when require_once later loads the same file. Clean up these entries after opcache_compile_file() returns, temporarily disabling the hash table destructor to avoid freeing SHM-backed entries. Cleanup is skipped during preloading where registrations must persist. Fixes https://github.com/php/php-src/issues/18714

« previous php.git-pulls (#35266) next »