Corveda / PHPSandbox

A PHP-based sandboxing library with a full suite of configuration and validation options.
https://phpsandbox.org
Other
220 stars 46 forks source link

Notice: constant PHP_EOL already defined #2

Closed caraffa closed 8 years ago

caraffa commented 8 years ago

Hi. First of all thanks for the outstanding job. Really useful. Now the problem. In the PHP code I need to vaildate/sandbox in my project I use extensively the constant PHP_EOL. If I write code using this constant, "as is", i. e. without defining it in advance by means of $sandbox->define_consts(), the validator rises an exception complaining about the fact that the PHP_EOL isn't defined. On the other hand, if I do define the const, upon execution of the sandboxed code (via $sanbox->execute("<code>")) the PHP engine issues a notice: "Notice: const PHP_EOL already defined". This should not be a big issue per se if i wouldn't use the SandBox in an Ajax context. Any, so to say, "uncontrolled" output from the PHP engine is deemed to break the response mechanism I set up for my ajax call. This forces me to suppress warning/notice output by means of the @ sign to prevent undesired output from breaking my response to the ajax call. This is clearly a patch. Suppressing the PHP engine output will surely hide any "wanted" notification about the state of execution of the sandboxed code, making thus the use of the Sandbox almost useless. Is there a way to circumvent this problem? Am I missing some important concept in the usage of this tool?

Thanks again

fieryprophet commented 8 years ago

Greetings caraffa,

What you want to do is simply whitelist the PHP_EOL constant, not redefine it. Like so:

$sandbox->whitelistConst('PHP_EOL');