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 ...