Web Designing, Web Development, Website Design, Website Development, SEO

0091 98233 72069

COGS: CUSTOMISED, OPTIMISED, GENERALISED WEB DESIGN & WEB DEVELOPMENT SOLUTIONS

__FILE__ in eval returns file name with some text eval()’d code

refer http://php.net/manual/en/language.constants.predefined.php

 

Note that __FILE__ has a quirk when used inside an eval() call. It will tack on something like “(80) : eval()’d code” (the number may change) on the end of the string at run-time. In normal use __FILE__ will return full physical path of the current executing file but if __FILE__ is use inside eval() function then it will return full physical path of the current executing file but some unwanted text suffixed to it something like (11): eval()’d code.

The workaround is:
$script = ‘echo __FILE__;’;
$script = str_replace(‘__FILE__’,”preg_replace(‘@\(.*\(.*$@’, ”, __FILE__,1)”,$script);
eval($script);