Problems with returning true or false in eval()'d code
Posted on
16th Feb 2014 07:03 pm by
admin
Hi guys,
Would appreciate some help with a problem when running eval() on a function that should return true or false.
Did you know?Explore Trending and Topic pages for more stories like this.
From php.net:
Quoteeval() returns NULL unless return is called in the evaluated code, in which case the value passed to return is returned.
Not sure if I'm missing something here but the following code illustrates that the function returns true/false as expected when run directly. However, the same function run using eval() never returns true:
Code: <?php
// Function to test what eval() returns...
function test()
{
$test = rand(1, 3);
return ($test === 1) ? TRUE : FALSE;
}
$eval = "test();";
$test = eval($eval); # expect this should set $test to TRUE for 1 in 3 attempts
echo ($test) ? 'eval returned true' : 'eval returned FALSE or NULL <br />';
// Now retest the function by calling it directly, not through eval...
$test2 = test();
echo ($test2) ? 'test returned TRUE' : 'test returned FALSE or NULL <br />'; # this behaves as expected...
?>
Hopefully it's something ridiculously obvious to someone out there...
No comments posted yet
Your Answer:
Login to answer
117
9
Other forums
SMTP server...
I recently found a tutorial online on SMTP authentification for sending emails from webpages, here i
Need help with cin setw
I made a program here is my code:
#include
#include
#i
Saving PHP output as a file
I wondered if anyone knows how to save the rendered output of a PHP script as a file?
I have
Multi Level Array Problem
hi all,
For example I have array like below:
$temp = array(array('north america', 'us'
Map.php
I am a complete beginner to PHP and am looking for some help with a program I am messing around with
Form submissing with PHP and JQuery/Ajax
I have searched everywhere, but cannot find a solution for this... I have worked all day trying to g
array & querys help/advice.
Ok so here goes , I have a mysql database and basically here's what I need to do.
// foreach
Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes
Undefined variable: adHTML
Hello:
While checking my site error logs, I've noticed one repetitive error that fills the lo
help connecting a form to php and then emailing the form
Ok. So, I made a form, and I need help to where when submitted, I get an email with the submitted de