I have been doing PHP stuff for almost one year and I have never used the function eval()
though I know the usage of it.
But I found many questions about it in
Using eval()
is a bad practice, and if it turns out to be necessary to achieve something, that is usually the sign of a underlying design error.
I can't think of any situation where it is necessary to use eval()
. (i.e. something can't be achieved using other language constructs, or by fixing a broken design.) Interested to see whether any genuine cases come up here where eval actually is necessary or the alternative would be horribly complex.
The only instance of where it could be necessary is for executing code coming from an external source (e.g. database records.) But this is a design error in itself IMO.