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
Text to picture Generator
Hello, i have found this script and it works really good^^ But i have one problem, i would like to c
Multiple arrays inside data
Hi,
Simple question. I have a column called "array" in my database, and inserted in
mail()
Hi all. I have a problem with emails. I am trying to set up a mail system where customers can subscr
Form File Upload
I've read through tons of resources and tutorials and as far as I can tell, my code is accurate, but
Simple MySQL query...
Hello,
How could I do a mysql query that does this: SELECT * WHERE date/time < 5minutes ag
PHP Programming error. Please help!
Hi there,
Am making a website for a friend and have encountered a problem that i need fixing
Take info from one coloum and move to another
Hi all,
I have this:
Code: [Select]$array = "SELECT stock_id FROM stocks WHERE stock_
Problem with "dynamic" index page
Hi. I have one question. In my index.php page I have this kind of code:
Code: // listaa sivut
Problem with shopcart code
Hello, I am having a bit of trouble being able to add a product to my shopcart. My mysql database i
update sql when refresh - php
hi
I have made a table (attachement)
the users can update the sql database using + or x bu