Wierdan, I still have a little question for you if you still watching this topic.
A strange thing happen. I need to do additional tests but I found a possible issue.
Your code works wonderfully but it seems that in certain circumstancies, the condition does not work.
Let me explain. So the code below works :
Code: Select all
$condition = new Condition('a', '>=', 'b');
test_function($condition);
//...
function test_function($rule)
{
$is_date=date("Ymd");
//$debut = intval(substr($fi['datedebut'],0, 6));
//$fin = intval(substr($fi['datefin'], 0, 6));
$dateactu = intval(substr($is_date, 0, 6));
$a=1;
$b=2;
// no more hacks
$rule->setContext(get_defined_vars());
if ($rule->evaluate())
{
var_dump(true);
print "ok";
// ...
}
else {
print "no ok";
}
}
In my case however, I do additional operation in the function, like a foreach loop that retreive the value of a and b from an array. It seems that when you initialise a and b in the same function several time and call the $rule->evaluate() function, the code seems to not be able to see that the variables value change.
If the condition is :
and I have an array of value for a and b like this :
Code: Select all
array[0][start]=1
array[0][end]=0
array[1][start]=2
array[1][end]=5
As you can see, at position [0], condition a > b is true if a=array[0][start] and b=array[0][end] and the condition should be false for [1]
In the code, I dynamically change the value of a and b from my array:
Code: Select all
function test_function($rule)
{
$is_date=date("Ymd");
//$debut = intval(substr($fi['datedebut'],0, 6));
//$fin = intval(substr($fi['datefin'], 0, 6));
$dateactu = intval(substr($is_date, 0, 6));
foreach ($array as $val){
$a=$val['start'];
$b=$val['end'];
// no more hacks
$rule->setContext(get_defined_vars());
if ($rule->evaluate())
{
var_dump(true);
print "ok";
// ...
}
else {
print "no ok";
}
}
}
(Please note that I have not tested yet the code above but I have the quite same structure in another code and this does not work for me, it is just to give you an idea. I will test THIS code as soon as I can to be sure.)
So, first 'ok' should be displayed and then 'no ok'. But for me, I still have some 'ok' ...
I am not really sure but it seems that PHP does not seems to see that the value for a and b have changed ...
An idea ?