|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-11-08 16:18 UTC] geompse at gmail dot com
Description: ------------ --- From manual page: http://www.php.net/function.opcache-compile-file "Compiles and caches a PHP script without executing it" --- As the documentation says, the script should not be executed (and it is not). But when trying to compile the current file, or an already included/required file, the function generate a Fatal Error and a Warning (wich can both by visually suppressed when using "@"). Practical use : updater script - overwrite files with new ones - force opcache recompilation The update is in the framework, and updates the framework. All already-included classes are already defined, and thus the compilation fail (or seems to fail, anyways it reports a failure). Test script: --------------- <?php error_reporting(E_ALL); ini_set('display_errors','On'); function coucou() { } echo 'Before'."\n"; opcache_compile_file(__FILE__); echo 'After'."\n"; ?> Expected result: ---------------- Before After Actual result: -------------- Before Fatal error: Cannot redeclare coucou() (previously declared in /root/compile.php:8) in /root/compile.php on line 8 Warning: Zend OPcache could not compile file /root/compile.php in Unknown on line 0 After PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
Terry, This may not be a "logical bug" but it is at least an undocumented behavior. To me, this is very misleading ("Fatal error" not fatal for the current script). Plus, combined with exception_handler this will do "weird shit". >> There should be an optional argument or configuration to disable both errors, or compile-scope error(s). See practical use, framework is designed for production usage. All errors are e-mailed, db-stored and eventually displayed. Any error is fatal (die). The function is doing what the documentation says it does. But it is doing more than that. Please correct either the function ("bug") or the documentation ("documentation problem"). Cordialement, GeompsePlease open your mind, I am talking about scopes, contexts and so on. This is ugly but works : system('php -r "opcache_compile_file(\''.__FILE__.'\')"'); This is clean but does not work : opcache_compile_file(__FILE__); (1) I don't see where the PHP architecture stops you from adding to the documentation "Notice : It will be compiled in the same compilation context" (2) It might be difficult/impossible to actually use another context, due to the architecture's limitations. You're the reference there.