PHP eval function

WBOY
Release: 2016-07-30 13:29:48
Original
1504 people have browsed it

eval() 函数把字符串按照 PHP 代码来计算。
该字符串必须是合法的 PHP 代码,且必须以分号结尾。
如果没有在代码字符串中调用 return 语句,则返回 NULL。如果代码中存在解析错误,则 eval() 函数返回 false。

For Example:

<code><span><span>class</span><span>Pass</span>{</span><span>private</span><span>$var1</span>;
        <span>private</span><span>$var2</span>;

        <span>public</span><span><span>function</span><span>__construct</span><span>(<span>$var1</span>,<span>$var2</span>)</span>{</span><span>$varchar</span>=<span>"this is a construct function,is hava two varchar $var1 and $var2"</span>;
            <span>eval</span>(<span>"\$varchar=\".$varchar.\";"</span>);
            <span>echo</span><span>$varchar</span>;
        }
    }

    <span>$P</span>=<span>new</span> Pass(<span>"HELLO"</span>, <span>"WORLD"</span>);</code>
Copy after login

输出结果:
this is a construct function,is hava two varchar HELLO and WORLD.

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了PHP eval函数,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!