CKTIS / PHP
Keyword include
Evaluate the named PHP file in the variable scope of the include site.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
include $filenameEvaluate the named PHP file in the variable scope of the include site. A return inside the file becomes the include expression’s result, otherwise successful inclusion normally returns 1. A missing file emits a warning and returns false, permitting subsequent execution.
$file=tempnam(sys_get_temp_dir(),"inc"); file_put_contents($file,'<?php $x += 2; return $x * 3;');
function readLocal($file){$x=4; $total=include $file; return [$x,$total];}
echo json_encode(readLocal($file)); unlink($file);
[6,18]
Examples
<?php
$file=tempnam(sys_get_temp_dir(),"inc"); file_put_contents($file,'<?php $x += 2; return $x * 3;');
function readLocal($file){$x=4; $total=include $file; return [$x,$total];}
echo json_encode(readLocal($file)); unlink($file);
Result
[6,18]