php-doc-en/reference/misc/functions/eval.xml
Kenneth Schwartz d259129bb0 use example.outputs[.similar] entity
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@181877 c90b9560-bf6c-de11-be94-00142212c4b1
2005-03-11 16:11:52 +00:00

96 lines
2.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.13 $ -->
<!-- splitted from ./en/functions/misc.xml, last change in rev 1.58 -->
<refentry id="function.eval">
<refnamediv>
<refname>eval</refname>
<refpurpose>Evaluate a string as PHP code</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>mixed</type><methodname>eval</methodname>
<methodparam><type>string</type><parameter>code_str</parameter></methodparam>
</methodsynopsis>
<simpara>
<function>eval</function> evaluates the string given in
<parameter>code_str</parameter> as PHP code. Among other things,
this can be useful for storing code in a database text field for
later execution.
</simpara>
<simpara>
There are some factors to keep in mind when using
<function>eval</function>. Remember that the string passed must
be valid PHP code, including things like terminating statements
with a semicolon so the parser doesn't die on the line after the
<function>eval</function>, and properly escaping things in
<parameter>code_str</parameter>.
</simpara>
<simpara>
Also remember that variables given values under
<function>eval</function> will retain these values in the main
script afterwards.
</simpara>
<simpara>
A <literal>return</literal> statement will terminate the evaluation of
the string immediately. As of PHP 4, <function>eval</function> returns
&null; unless <literal>return</literal> is called in the evaluated
code, in which case the value passed to <literal>return</literal> is
returned. In case of a parse error in the evaluated code,
<function>eval</function> returns &false;.
In case of a fatal error in the evaluated code, the whole script exits.
In PHP 3, <function>eval</function> does not return a value.
</simpara>
<para>
<example>
<title>
<function>eval</function> example - simple text merge
</title>
<programlisting role="php">
<![CDATA[
<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
This is a $string with my $name in it.
This is a cup with my coffee in it.
]]>
</screen>
</example>
</para>
&tip.ob-capture;
<para>
See also <function>call_user_func</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->