Re: Handling exit in eval
| From: | Richard Quadling | Date: | Mon, 14 Mar 2011 16:29:54 +0000 |
| Subject: | Re: Handling exit in eval | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-311834@lists.php.net to get a copy of this message | ||
On 14 March 2011 12:14, DELiTH <tb@bytecode.se> wrote:
> Richard Quadling wrote:
>
>> 2011/3/14 Richard Quadling <rquadling@gmail.com>:
>>
>> And where is my UNDO button.
>>
>> Essentially, having exit in the eval code is no different to having it
>> in non-eval code. eval isn't a separate entity which can be
>> terminated.
>>
>> So, code the eval code differently.
>>
>> If you can provide some examples, maybe we can come up with a better solution.
>>
>>
>>
>
> I'm developing a kind of sandbox where you will be able to run a script
> without affecting your current context. The script is loaded and parsed
> which gives me the opportunity to allow or deny functions and classes
> used in the script.
> The only problem I have so far is the exit function which, it if is
> allowed, terminates the calling script as well as the eval'ed script.
>
> By using a return the problem is solved as long as the user doesn't
> write a function containing an exit.
>
> Here is a simple script thet the user might write (probably as useful as
> a "Hello, world!".
>
> <?php
> function DoSomethingOrExit($test) {
> if($test == 1) {
> exit;
> }
> return;
> }
>
> DoSomethingOrExit(0);
> echo "Hello";
> DoSomethingOrExit(1);
> echo ", world!";
> exit;
> echo "Bye";
> ?>
>
> By replacing exit with return this code will echo "Hello, world!" before
> returning without echoing "Bye".
>
>
> Another perfect solution would be if there was a way to trigger an error
> within the eval'ed script that "crashes" it and returns to the calling
> script. But then it just comes back to the entity-problem as you pointed
> out.
>
>
> /Thomas
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Why not just invoke a separate instance of PHP using exec() ?
Or take a look at runkit/runkit_Sandbox :
http://uk.php.net/manual/en/book.runkit.php
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY