Edit report at https://bugs.php.net/bug.php?id=60171&edit=1
ID: 60171
Comment by: invictible at live dot co dot uk
Reported by: invictible at live dot co dot uk
Summary: Suggestion for new function
Status: Wont fix
Type: Feature/Change Request
Package: Unknown/Other Function
Operating System: Windows
PHP Version: 5.3.8
Block user comment: N
Private report: N
New Comment:
So, instead of having to run an if statement in eval, you can simply do
something like compare('5>6 || 2<3');
So, you can perform comparisons and logical operations in a way that can't
currently be performed without eval().
I saw php.net/version_compare although, it doesn't seem to cater for logical
operations such as && and ||.
If there is another alternative then, feel free to tell me it.
Previous Comments:
------------------------------------------------------------------------
[2011-10-30 15:37:35] artificialmagic at hotmail dot com
Who would ever think this was useful?
------------------------------------------------------------------------
[2011-10-30 03:39:46] invictible at live dot co dot uk
Expressions such as >, >+ aka something like the comparison operators except,
in function form.
------------------------------------------------------------------------
[2011-10-30 00:52:48] [email protected]
This is the purpose of eval (though it would probably be better â including
versatile â to parse the expression yourself), the "security issues" (really,
input validation) can be handled by analyzing the tokens in the strings; see
token_get_all().
Besides, this request is very vague â for instance it doesn't specify which
subset of the expressions space would be admissible and gives a rationale for
it.
Won't fix.
------------------------------------------------------------------------
[2011-10-29 21:28:06] invictible at live dot co dot uk
Description:
------------
I've been looking for a solution on PHP as I need some way to evaluate
expressions within strings.
Since with if:
$str = '5>6';
if($str)
Would evaluate as true regardless of the expression.
A good possible solution for this may be a function for evaluating the
expressions in the string, eg. evalexp($str); which would return true or false
based on the expression within the string.
Eval is an alternative however, it can create security issues when used with
user provided content for obvious reasons.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60171&edit=1