When (if ever) will you do this in PHP?

I am looking through the Wordpress plugin code and found the following:

eval( '?>' . $foo . '<?php ' );

I am curious if there is any particular situation that I do not suspect is that this will be the correct way to output the variable $foo. Is this just a case where the plugin author is stupid or is there something I should know? I would just use echo...

UPDATE:

Thanks for the great feedback. I now feel that I do not think about the template. In particular, this happens in the WP Super Cache plugin. I think I will need to take a closer look to see if this needs to be done. I thought Super Cache cached html Wordpress output after PHP has already been processed ...

+5
source share
3 answers

$foo - , () PHP-. , PHP- eval 'ed.

, eval, , , , . (..: , $foo , eval .)

php? / .

+6

. $foo , <?=$code();?> .

PHP eval , HTML. eval() :

include("data:,$foo");  // treat $foo string as if it was include script
+2

Let me repeat again: crap

If eval () is the answer, you are almost certainly asking the wrong question.

Rasmus Lerdorf

-1
source

All Articles