reference/misc/functions/eval.xml
68308f0095c6ebf0d19afa72f2bac0a9f194e77d
...
...
@@ -15,6 +15,16 @@
15
15
<para>
16
16
Evaluates the given <parameter>code</parameter> as PHP.
17
17
</para>
18
+
<para>
19
+
The code being evaluated inherits the
20
+
<link linkend="language.variables.scope">variable scope</link>
21
+
of the line on which the <function>eval</function> call occurs.
22
+
Any variables available at that line will be available for reading and
23
+
modification in the evaluated code.
24
+
However, all functions and classes defined will be defined in the global namespace.
25
+
In other words, the compiler considers the evaluated code as if it were a
26
+
separate <link linkend="function.include">included</link> file.
27
+
</para>
18
28
<caution>
19
29
<para>
20
30
The <function>eval</function> language construct is <emphasis>very dangerous</emphasis>
...
...
@@ -37,12 +47,12 @@
37
47
Valid PHP code to be evaluated.
38
48
</para>
39
49
<para>
40
-
The code mustn't be wrapped in opening and closing
50
+
The code must not be wrapped in opening and closing
41
51
<link linkend="language.basic-syntax.phpmode">PHP tags</link>, i.e.
42
52
<literal>'echo "Hi!";'</literal> must be passed instead of
43
-
<literal>'&lt;? echo "Hi!"; &gt;'</literal>. It is still possible to leave and
44
-
reenter PHP mode though using the appropriate PHP tags, e.g.
45
-
<literal>'echo "In PHP mode!"; ?&gt;In HTML mode!&lt;? echo "Back in PHP mode!";'</literal>.
53
+
<literal>'&lt;?php echo "Hi!"; ?&gt;'</literal>. It is still possible to leave and
54
+
re-enter PHP mode though using the appropriate PHP tags, e.g.
55
+
<literal>'echo "In PHP mode!"; ?&gt;In HTML mode!&lt;?php echo "Back in PHP mode!";'</literal>.
46
56
</para>
47
57
<para>
48
58
Apart from that the passed code must be valid PHP. This includes that all statements
...
...
@@ -70,9 +80,10 @@
70
80
<para>
71
81
<function>eval</function> returns &null; unless
72
82
<literal>return</literal> is called in the evaluated code, in which case
73
-
the value passed to <literal>return</literal> is returned. If there is a
74
-
parse error in the evaluated code, <function>eval</function> returns
75
-
&false; and execution of the following code continues normally. It is
83
+
the value passed to <literal>return</literal> is returned. As of PHP 7, if there is a
84
+
parse error in the evaluated code, <function>eval</function> throws a ParseError exception.
85
+
Before PHP 7, in this case <function>eval</function> returned
86
+
&false; and execution of the following code continued normally. It is
76
87
not possible to catch a parse error in <function>eval</function>
77
88
using <function>set_error_handler</function>.
78
89
</para>
79
90