Matthieu Napoli
Matthieu Napoli

Reputation: 49703

Is it possible to include PHP code that is in memory?

Say I have a variable containing PHP code, can I include its content as if it was a normal PHP file ?

For example, the PHP code could be a class declaration.

Upvotes: 0

Views: 301

Answers (3)

Wesley van Opdorp
Wesley van Opdorp

Reputation: 14951

You don't have a variable containing php code. You have a string. You can execute a string as php with the evil eval function, but puppies AND kittens will die!

Upvotes: 8

TJHeuvel
TJHeuvel

Reputation: 12618

You could use eval to evaluate any code that you have in your string, however it is evil. What exactly are you trying to do?

Upvotes: 4

genesis
genesis

Reputation: 50982

eval($your_variable);

Be aware about security holes!This is very dangerous and should NOT be based on user's input !

Upvotes: 7

Related Questions