Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working again #35

Closed
Jobians opened this issue Oct 12, 2023 · 1 comment
Closed

Not working again #35

Jobians opened this issue Oct 12, 2023 · 1 comment

Comments

@Jobians
Copy link

Jobians commented Oct 12, 2023

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

@Jobians Jobians closed this as completed Oct 12, 2023
@Jobians Jobians reopened this Oct 12, 2023
@Jobians Jobians closed this as completed Oct 12, 2023
@Jobians
Copy link
Author

Jobians commented Oct 12, 2023

Fixed

Changed

$sandbox->defineVars(['Server']);

To

$sandbox->defineVars(['Server' => $Server]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant