On the definition and usage of PHP eval () function, a brief talk on eval_php tutorial

Source: Internet
Author: User

On the definition and usage of PHP eval () function, on eval


The eval () function calculates the string according to the PHP code.

The string must be a valid PHP code and must end with a semicolon.

If no return statement is called in the code string, NULL is returned. If there is a parsing error in the code, the eval () function returns FALSE.

Grammar

Parameters Description
Phpcode Necessary. Specifies the PHP code to be computed.

Hints and Notes

Note: The return statement terminates the calculation of the string immediately.

Note: This function is useful for code storage that is made available for future calculations in a database text field.

Example

<?php$string = "Beautiful"; $time = "Winter"; $str = ' This is a $string $time morning! '; echo $str. "

Output:

This is a $string $time morning!
This is a beautiful winter morning!

The eval () function is also useful in the CodeIgniter framework. In the/system/database/db.php file, a class ci_db is dynamically defined according to the configuration of the system, with the following code snippet:

if (! isset ($active _record) OR $active _record = = TRUE) {require_once (basepath. ' database/db_active_rec.php ');  if (! class_exists (' ci_db ')) {  eval (' class ci_db extends Ci_db_active_record {} ');}} else {if (! class_exists (' C i_db ') {  eval (' class ci_db extends Ci_db_driver {} ');}}  Require_once (basepath. ' database/drivers/'. $params [' Dbdriver ']. ' /'. $params [' Dbdriver ']. ' _driver.php ');  Instantiate the DB adapter $driver = ' ci_db_ '. $params [' Dbdriver ']. ' _driver '; $DB = new $driver ($params);

This article on the PHP eval () function definition and usage is the small part of the whole content to share to everyone, I hope to give you a reference, but also hope that we have a lot of support to help guests home.

http://www.bkjia.com/PHPjc/1136619.html www.bkjia.com true http://www.bkjia.com/PHPjc/1136619.html techarticle on the definition and usage of the PHP eval () function, the eval eval () function computes the string in PHP code. The string must be a valid PHP code and must end with a semicolon. If ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.