php dynamic code compilation

Hello all.
I wonder how can I compile a php code stored in a variable dynamically.
In languages such C# is there something called Reflection. PHP has its own implementation but I can’t find a way to make it.

Is this possible?

PHP: eval - Manual

I was looking in the wrong way.

Thank you.

“if eval is the answer… you are asking the wrong question” that’s an old quote :wink:

what specifically you want to do ? eval() should not be used.

Well, I want to create a translation library.
The translations are stored in a database and I shouldn’t query the db every time a client request the page, because of this, I create a script that query the db and store the translations in a text file every time a translation phrase is inserted.
I use the following format:

array('hola' => array('en'=>'hello',  'po'=> 'oi')

and then, instead query the db when a translation request comes, I just eval() the code saved in the mentioned file.
The main language is spanish, that is why I use the word as the key of the associative array.

heh, you are indeed asking the wrong question :stuck_out_tongue:

Almost all database access libraries support the use of Cached sql statements, they query the database once, then the result is stored on a file, in serialized form.

At least PEAR MDB2, adodb just work.

In any case, YOU DONT eval() your example code, you serialize() and store, then read file and unserialize().

Finally, PHP’s eval() is very slow and more importantly, almost unsecurable, you dont really want it, trust me :wink: