LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2019, 08:09 PM   #1
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Question php function_exists("eval") fails


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?
 
Old 12-17-2019, 09:37 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
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:
Code:
$evalok= FALSE;
@eval('$evalok= TRUE;');

Last edited by NevemTeve; 12-17-2019 at 10:22 PM.
 
2 members found this post helpful.
Old 12-17-2019, 10:25 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
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.
 
1 members found this post helpful.
Old 12-18-2019, 06:46 AM   #4
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,616

Rep: Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554Reputation: 2554
Quote:
Originally Posted by astrogeek View Post
That does not directly answer your question
Why not?

The question was "Why does function_exists("eval") return false?" and the answer is "eval is a language construct and not a function".


An interesting follow-up question might be why eval (and others, e.g. isset) are implemented as language constructs instead of functions.
 
1 members found this post helpful.
Old 12-18-2019, 10:37 AM   #5
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490

Original Poster
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by NevemTeve View Post
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 View Post
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.
 
Old 12-18-2019, 11:32 AM   #6
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490

Original Poster
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
One more remark:
Quote:
Originally Posted by dogpatch View Post
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.
 
Old 12-18-2019, 04:14 PM   #7
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490

Original Poster
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Smile

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.

I will now mark this thread as 'Solved'
 
  


Reply

Tags
eval, function_exists, php



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ preprocessor "/lib/cpp" fails sanity check C++ preprocessor "/lib/cpp" fails san mutetikasikali Linux - Software 3 01-25-2014 06:57 AM
how to send the output of a command in a file defined by a eval $"$var1" toordog Programming 3 07-07-2010 04:26 PM
Help With Java Problem Please"""""""""""" suemcholan Linux - Newbie 1 04-02-2008 06:02 PM
Package Installation fails during OpenSuse Eval 10.0 DVD install jimisola SUSE / openSUSE 2 12-02-2005 08:00 PM
PHP eval() function nxny Programming 2 01-09-2003 02:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration