ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If i call function_exists("eval") on my server, it returns false. But the function eval() exists and works fine.
This is mostly a curiosity question: Please don't lecture me on how i shouldn't use eval() because it's potentially dangerous. If my hosting service were to disable eval(), i could work around that, but would like to know how to tell if this function is avalable.
I can call get_defined_functions() and get a list about a mile long which does indeed include eval() along with other potentially 'dangerous' php functions.
If i call ini_get('disable_functions'), i get an empty list.
Other functions, for example function_exists("exec") returns true. Why does function_exists("eval") return false?
It might treat built-in language constructs and user-defined functions differently. (The documentation mentions 'include' as an example: it also looks like a function, but function_exists gives FALSE for it.)
> would like to know how to tell if this function is available.
I would try this:
NevemTeve appears to be on the right track - eval is not a function. From the PHP manual:
Code:
Note: Because this is a language construct and not a function, it cannot be called using variable functions.
That does not directly answer your question, but it shows that functions and language constructs are certainly not equivalent in the eyes of PHP itself.
It might treat built-in language constructs and user-defined functions differently.
That does indeed answer my first question. Thank you.
Quote:
Originally Posted by NevemTeve
I would try this:
Code:
$evalok= FALSE;
@eval('$evalok= TRUE;');
Am not sure how this would tell me if the function is available. What i've done is enclose your test after the following
Code:
function myException($exception) {
echo "<b>Exception:</b> " . $exception->getMessage();
}
set_exception_handler('myException');
which allows me to print my own error message to the screen. This works if i try to use an undefined function. But my script still dies at that point. Still haven't discovered how to recover and continue executing after the error. Nor am i sure that this would work if my hosting service were to disable eval() or some other function or construct.
I can call get_defined_functions() and get a list about a mile long which does indeed include eval() along with other potentially 'dangerous' php functions.
Must have been seeing things. Now when i run get_defined_functions(), i do not see eval anywhere in the returned list.
Final note: from this web page, I found the following:
Quote:
- Language constructs in some cases may be able to bypass error handling mechanisms
- While functions can be disabled in PHP via the configuration file, language constructs cannot.
(emphasis added)
- which means my original concern was over nothing. It would appear that eval() can never be disabled, so i have no need to wonder.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.