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.

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 Like 9 Dislike
Previous forums Next forums
Other forums

Calander Basic Spript help
hi, just starting out with PHP and have the following script:

<?php
//This gets t

is this the proper use of mysql_real_escape_string() to prevent sql injections?
i was wondering is this the proper use of mysql_real_escape_string() to prevent sql injections? any

SCO Unix
I know this might not be the place to ask, but, can anyone tell me if SCO Unix comes with PHP built

Firewall / visited websites logger
Hi. I have a firewall implementation and I want to log all the websites visited on the machine. S

Create or replace package is ending ORA-21700
Database 9.2.0., patch 8 (9.2.0.8.0).
I trying run
create or replace package ....etc.

Links not updating
I'm trying to fuel a simple navigation system for a news section. It works fine when it comes to ret

Calculating n! using vector
#include
#include
#include

using

DateObject and Nulls
Hi all,

I have an array mapped to a value object. One of the items in the array is a PHP Date

Passing JS to PHP
So I have the following
Code: <?php
getdetails(?><script type="text/

Prevention Help
How can I use PHP or any other language (feel free to move this thread) to prevent users doing scree

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash