News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Gonzalo Ayuso's Blog:
How to use eval() without using eval() in PHP
March 13, 2012 @ 10:09:52

In this new post Gonzalo Ayuso talks about "using eval without using eval" in PHP applications - executing PHP code without having to use the eval function to do it.

Yes I know. Eval() is evil. If our answer is to use eval() function, we are probably asking the wrong question. When we see an eval() function all our coding smell's red lights start flashing inside our mind. Definitely it's a bad practice. But last week I was thinking about it. How can I eval raw PHP code without using the eval function, and I will show you my outcomes.

He includes some sample code showing a basic script with a class and a loop executing normally, then an "eval version" that puts it all in a string and executes it. He offers a different method - not an ideal one since it requires being able to write to the local file system, but prevents the need for eval - writing the PHP code to a temporary file and using a "fake eval" to pull it in.

0 comments voice your opinion now!
eval execute string code temporary file include


blog comments powered by Disqus

Similar Posts

NetTuts.com: Refactoring Legacy Code: Part 4 - Our First Unit Tests

DevShed: Handling File Data with the Facade Pattern in PHP 5

NetTuts.com: Refactoring Legacy Code: Part 9 - Analyzing Concerns

Stuart Herbert's Blog: PHP Components: PHP Components: Shipping Unit Tests With Your Component

PHPMaster.com: Code Templates, AutoHotKey, and Ditto: Speeding Up Development


Community Events





Don't see your event here?
Let us know!


testing wordpress introduction podcast interview developer configure install refactor opinion list language code release community series threedevsandamaybe framework unittest laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework