3 ms·
The main issues with using eval come when eval has access to the scope of whatever is calling it, as it can make unpredictable changes. Just compiling and runni
by LeafStorm 15y ago
The main issues with using eval come when eval has access to the scope of whatever is calling it, as it can make unpredictable changes. Just compiling and running code constructed at runtime isn't a bad idea in itself, as long as you use proper techniques to ensure that users can't do code injection.
- thwarted 15y agoThat's a good point, and is an language design/implementation specific condition. PHP doesn't create a new stack frame for eval'ed code, so it runs right in the context of the calling function. In constrast, LambdaMOO does create a separate stack frame, which is subjected to the same scope rules as any other function call. You can control if it does or not in perl (by stuffing some additional syntax into the eval'ed string). But the usual issue that is bandied about is how it's inefficient because it needs to invoke the code parser. Searching hacker news for eval shows the wide range of positions, a lot (but not a wide majority) just parrot the inefficiency argument. But there are also a few posts with solid reasons to use eval too.