eval('class this { ');
eval('function this($l1,$l2) {
if($l1==0) { throw new ErrorException("error"); }
echo $l1.$l2;
}}');
try {
$t = new this(0,1);
}
catch(Exception $e) {
echo $e->getMessage();
}
Why is this code not working?
Errors:
Parse error: syntax error, unexpected $end, expecting T_FUNCTION in .......(4) : eval()'d code on line 1
Parse error: syntax error, unexpected '}' in.......(9) : eval()'d code on line 4
Fatal error: Class 'this' not found in .......on line 12
You can’t
eval()an unclosed statement likeclass this {. You’d have to put the entire block into one string and run theeval()once.That said, there is probably no reason to use
eval()in the first place. What are you trying to do?