What problem will generate E_COMPILE_WARNING in PHP?

I searched a bit on Google as well as SO and couldn't find the answer to this simple question:

What problem will generate E_COMPILE_WARNING in PHP?

A PHP manual post on docs talks about E_COMPILE_WARNING :

Compilation warnings (non-fatal errors). This is similar to E_WARNING, except that it is generated by the Zend Scripting Engine.

But I'm not sure what this will represent. What is the difference between regular E_WARNING and the warning raised by the Zend Scripting Engine? Can someone explain and provide a code snippet, if applicable?

+6
source share
2 answers

Basically, the difference between E_WARNING and E_COMPILE_WARNING is that E_COMPILE_WARNING generated while the script is still compiling.

E_COMPILE_WARNING is similar to E_COMPILE_ERROR in that it is generated at compile time, but E_COMPILE_WARNING does not prevent script execution by E_COMPILE_ERROR . Compare this to the relationship between E_ERROR and E_WARNING , where the former stops execution and the latter allows execution to continue.

For example, the following code generates E_COMPILE_WARNING :

 <?php echo "\n"; echo "Hello World"; echo "\n\n"; var_dump(error_get_last()); declare(foo='bar'); ?> 

exit:

 Warning: Unsupported declare 'foo' in e_compile_warning.php on line 6 Hello World array(4) { ["type"]=> int(128) ["message"]=> string(25) "Unsupported declare 'foo'" ["file"]=> string(124) "e_compile_warning.php" ["line"]=> int(6) } 

Notice how the warning is displayed before another exit (even if "Hello World" came first in the source), and the var_dump on line 5 refers to the error that occurs on line 6. PHP compiles the script, doesn't like declare(foo='bar'); , but returns and executes the script anyway (unlike E_COMPILE_ERROR as $this = 2; ), which immediately stopped execution (and compilation).

Hope this helps!

+9
source

You can directly display an exit warning using the following code:

 $cmd = "declare(foo='bar');"; eval($cmd); 
+1
source

Source: https://habr.com/ru/post/905385/


All Articles