Not working again
Closed this issue · 1 comments
Please I don't know why this not working
<?php
require_once 'vendor/autoload.php';
use PHPSandbox\PHPSandbox;
function test($string){
return 'Hello ' . $string;
}
class Server {
public function sendMessage($message) {
echo "Sending message: " . $message;
}
}
$Server = new Server();
$sandbox = new PHPSandbox();
$sandbox->whitelistClass("Server");
$sandbox->whitelistVar("Server");
$sandbox->defineVars(['Server']);
$result = $sandbox->execute('<?php
echo $Server->sendMessage("ping google.com");
?>');
var_dump($result);
Fatal error: Uncaught PHPSandbox\Error: Cannot define unnamed variable! in /data/data/com.termux/files/home/php/bota/vendor/corveda/php-sandbox/src/PHPSandbox.php:7195
Stack trace:
#0 /data/data/com.termux/files/home/php/bota/vendor/corveda/php-sandbox/src/PHPSandbox.php(2774): PHPSandbox\PHPSandbox->validationError('Cannot define u...', 203, NULL, '')
#1 /data/data/com.termux/files/home/php/bota/vendor/corveda/php-sandbox/src/PHPSandbox.php(2792): PHPSandbox\PHPSandbox->defineVar(0, 'Server')
#2 /data/data/com.termux/files/home/php/bota/test.php(21): PHPSandbox\PHPSandbox->defineVars(Array)
#3 {main}
thrown in /data/data/com.termux/files/home/php/bota/vendor/corveda/php-sandbox/src/PHPSandbox.php on line 7195
Fixed
Changed
$sandbox->defineVars(['Server']);
To
$sandbox->defineVars(['Server' => $Server]);