PHP eval() Function Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report PHP eval() function in PHP is an inbuilt function that evaluates a string as PHP code. Syntax: eval( $string ) Parameters: This function accepts a single parameter as shown in the above syntax and described below. $string: It must consist of a valid PHP code to be evaluated but should not contain opening and closing PHP tags. Note: All statements must be properly terminated using a semicolon. For example, initializing the string as 'echo "Geeks for Geeks"' will cause a parse error. To rectify, need to initialize as 'echo "Geeks for Geeks";'. Return Value: Returns NULL unless a return statement is called in the input string containing PHP code. Then the value is returned. In case of a parse error in the input string, the function returns FALSE. Examples: Input : $age = 20; $str = "I am $age years old" eval("\$str = \"$str\";"); Output : I am 20 years old Input : $str = 'echo "Geeks for Geeks";'; echo eval($str). "\n"; Output : Geeks for Geeks Below programs illustrate the use of eval() function: Program 1: php <?php $age = 20; $str = 'My age is $age'; echo $str. "\n"; eval("\$str = \"$str\";"); echo $str. "\n"; ?> Output:My age is $age My age is 20 Program 2: php <?php $str = 'echo "Geeks for Geeks";'; echo eval($str). "\n"; ?> Output:Geeks for Geeks Reference: https://www.php.net/manual/en/function.eval.php Comment More infoAdvertise with us Next Article PHP | boolval() Function R RICHIK BHATTACHARJEE Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP ceil( ) Function We have often used the ceiling function in mathematical problems to round up a decimal number to next greater integral value. PHP provides us with a built-in function ceil() to perform such operation. The ceil() function is a built-in function in PHP and is used to round a number to the nearest grea 1 min read PHP each() Function The each() function is an inbuilt function in PHP and is used to get the current element key-value pair of the given array to which the internal pointer is currently pointing. After returning the key and value of the current element the internal pointer is incremented by one in the array. Note: You 2 min read PHP | ftell( ) Function The ftell() function in PHP is an inbuilt function which is used to return the current position in an open file. The file is sent as a parameter to the ftell() function and it returns the current file pointer position on success, or FALSE on failure.Syntax:Â Â ftell( $file ) Parameters Used: The ftel 2 min read PHP | boolval() Function The boolval() function is an inbuilt function in PHP which gives the Boolean value for a given expression. Syntax: boolean boolval( $expr ) Parameter: This function accepts only one parameter as shown in above syntax and described below: $expr: The expression or the scalar which you want to change i 3 min read PHP end() Function The end() function is an inbuilt function in PHP and is used to find the last element of the given array. The end() function changes the internal pointer of an array to point to the last element and returns the value of the last element.Syntax:end($array)Parameters:This function accepts a single par 2 min read PHP | floatval() Function The floatval() function is an inbuilt function in PHP which returns the float value of a variable. Syntax: float floatval ( $var ) Parameters: This function accepts one parameter which is mandatory and described below: $var: The variable whose corresponding float value will be returned. This variabl 1 min read Like