using Microsoft.VisualStudio.Scripting; // Create a new script context ScriptContext context = new ScriptContext(); // Set some variables for use in the script context.SetVariable("Name", "John"); context.SetVariable("Age", 30); // Execute a script and retrieve the result object result = context.Execute("var message = 'Hi, ' + Name + '! You are ' + Age + ' years old.'; message;");
use Zend\Server\{Server, AbstractContext}; // Define a new script context class MyContext extends AbstractContext { protected $name; public function __construct(array $options = []) { parent::__construct($options); $this->name = $options['name'] ?? 'World'; } public function sayHello() { return "Hello, {$this->name}!"; } } // Create a new server and add the context $server = new Server(); $context = new MyContext(['name' => 'John']); $server->setObject($context); // Execute a remote function echo $server->call('MyContext.sayHello'); // Output: Hello, John!Package Library: Zend\Server