Re: Handling exit in eval

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2011/3/14 Thomas BjÃrk <tb@xxxxxxxxxxx>:
> Is there any way to emulate an exit in eval without exiting the calling
> script.
>
> <?php
> $s = 'echo "Shows"; exit; echo "Doesn\'t show"; ';
> eval($s);
> echo "Never comes here";
> ?>
>
>
> I would like to do something like this:
> <?php
> $s = 'echo "Shows"; exit; echo "Doesn\'t show"; ';
>
> function MakeItStop() {
> Â// Do something to make the eval stop
> Â// without halting the script
> }
>
> $s = str_replace('exit;', 'MakeItStop();', $s);
>
> eval($s);
> echo "Never comes here";
> ?>
>
>
> A simple return would fix it IF the return isn't located within a
> function.
>
>
> Any good suggestions?
>
> Thanks in advanced
> Thomas BjÃrk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Can you provide a more realistic example?

Just don't code anything after the last line of code that contains the
exit? Surely.

http://uk.php.net/manual/en/function.eval.php does say that ...

"A return statement will immediately terminate the evaluation of the string ."

So, there's your answer I suppose.

Replace "exit" with "return".

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux