mirror of
https://github.com/php/doc-it.git
synced 2026-03-24 07:32:12 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@339831 c90b9560-bf6c-de11-be94-00142212c4b1
152 lines
4.6 KiB
XML
152 lines
4.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 0d66a6cf2c0cad946dd8b766ac6ea09b96989114 Maintainer: reghe Status: ready -->
|
|
<refentry xml:id="function.eval" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>eval</refname>
|
|
<refpurpose>Esegue una stringa come codice PHP</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>mixed</type><methodname>eval</methodname>
|
|
<methodparam><type>string</type><parameter>code</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Esegue la data stringa <parameter>code</parameter> come codice PHP.
|
|
</para>
|
|
<caution>
|
|
<para>
|
|
<function>eval</function> è un costrutto del linguaggio <emphasis>molto pericoloso</emphasis>
|
|
perché permette l'esecuzione di codice PHP arbitrario. <emphasis>Il suo uso è pertanto
|
|
sconsigliato.</emphasis> Se si è certi che non esistono altre soluzioni al posto di usare
|
|
<function>eval</function>, fare particolare attenzione a <emphasis>non inserire codice fornito
|
|
dall'utente</emphasis> senza averlo preventivamente validato.
|
|
</para>
|
|
</caution>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Codice PHP valido da eseguire.
|
|
</para>
|
|
<para>
|
|
Il codice non deve essere incluso nei <link linkend="language.basic-syntax.phpmode">tag
|
|
di apertura e chisura</link> di PHP. Ad esempio
|
|
<literal>'echo "Ciao!";'</literal> è corretto invece di
|
|
<literal>'<? echo "Ciao!"; >'</literal>. È comunque possibile uscire e
|
|
rientrare nella modalità PHP attraverso l'utilizzo dei tag PHP appropriati, ad esempio:
|
|
<literal>'echo "In PHP mode!"; ?>In HTML mode!<? echo "Back in PHP mode!";'</literal>.
|
|
</para>
|
|
<para>
|
|
Oltre a questo, valgono tutte le regole del codice PHP. Questo include l'inserimento al termine
|
|
di ogni istruzione del punto e virgola.
|
|
<literal>'echo "Ciao!"'</literal> per esempio causerà un parse error, mentre
|
|
<literal>'echo "Ciao!";'</literal> funzionerà.
|
|
</para>
|
|
<para>
|
|
Un'istruzione <literal>return</literal> causa immediatamente la terminazione del codice
|
|
in corso di esecuzione dalla <function>eval</function>.
|
|
</para>
|
|
<para>
|
|
L'ambito di esecuzione è ristretto a dove <function>eval</function> viene chiamata. Quindi qualsiasi
|
|
variabile definita o modificata all'interno di <function>eval</function> rimarrà visibile dopo
|
|
la sua terminazione.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
<function>eval</function> ritorna &null; a meno che
|
|
non venga richiamato <literal>return</literal> nel codice da valutare, in tal caso
|
|
il valore passato a <literal>return</literal> viene ritornato. Se avviene un
|
|
parse error nel codice valutato, <function>eval</function> ritorna
|
|
&false; e l'esecuzione del codice seguente continua normalmente. Non
|
|
è possibile catturare un parse error in <function>eval</function>
|
|
usando <function>set_error_handler</function>.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Esempio di <function>eval</function> - semplice unione di testo</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>
|
|
</refsect1>
|
|
|
|
<refsect1 role="notes">
|
|
&reftitle.notes;
|
|
|
|
¬e.language-construct;
|
|
|
|
&tip.ob-capture;
|
|
<note>
|
|
<para>
|
|
In caso di fatal error nel codice valutato, l'intero script termina.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>call_user_func</function></member>
|
|
</simplelist>
|
|
</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:"~/.phpdoc/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
|
|
-->
|