PHP "Eval is Evil"

Posted April 7, 2010

I keep seeing something which is beginning to annoy me - I keep seeing all these forum and blog comments saying how terrible PHP's "eval" instruction is, and how there is no reason what-so-ever to use it.

I wish people would keep their opinions to themselves simply when they cannot think of an instance when to use it. Just because you cannot think of a good time to use it, doesn't mean there aren't any.

Here's a real-world example. I am writing a small framework (I won't go into what it does - it's a moot point). The framework allows the developer to define interfaces. At runtime, the framework must implement these interfaces. How do you do this outside the realm of an eval? Short of physically creating a source file an "include"ing it, I cannot see any other way to perform such a task.

Ultimately, unless you have worked on every conceivable type software (which is impossible), you really cannot ever make a blanket statement like "oh, there is no reason to ever use this or that". That's simply being an opinionated prat, and perhaps you need to use that massive brain of yours to control yourself for blurting or typing out a load of rubbish.

Comments

There are no comments for this post.

No comments found

Add comment

Visit my Friends and Family

If you've enjoyed my site, please take a moment to visit my friends and family, many of whom have some interesting insights, and entertaining thoughts and ideas.