Skip to content

Commit 2f2e5be

Browse files
committed
fix function order params
1 parent 93b74be commit 2f2e5be

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Expression.lib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ function pfx($tokens, $vars = array())
498498
}
499499
$args[] = $stack->pop();
500500
}
501-
$stack->push($reflection->invokeArgs($args));
501+
$stack->push($reflection->invokeArgs(array_reverse($args)));
502502
}
503503
// if the token is a number or variable, push it on the stack
504504
} else {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "optimistex/yii2-expression",
33
"description": "Taken from http://www.phpclasses.org/browse/file/11680.html, cred to Miles Kaufmann",
44
"type": "yii2-extension",
5-
"version": "2.0.1.2",
5+
"version": "2.0.1.3",
66
"license": "MIT",
77
"authors": [
88
{

tests/Expression.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,41 @@ public function testBug_1()
301301
// */
302302

303303
public function testFormulaWithBrackets()
304+
{
305+
$e = new Expression();
306+
$e->suppress_errors = true;
307+
$e->functions = [
308+
'p1' => function ($p1, $p2, $p3, $p4, $p5) {
309+
return $p1;
310+
},
311+
'p2' => function ($p1, $p2, $p3, $p4, $p5) {
312+
return $p2;
313+
},
314+
'p3' => function ($p1, $p2, $p3, $p4, $p5) {
315+
return $p3;
316+
},
317+
'p4' => function ($p1, $p2, $p3, $p4, $p5) {
318+
return $p4;
319+
},
320+
'p5' => function ($p1, $p2, $p3, $p4, $p5) {
321+
return $p5;
322+
},
323+
];
324+
325+
$data = [
326+
'p1(1, 2, 3, 4, 5)' => 1,
327+
'p2(1, 2, 3, 4, 5)' => 2,
328+
'p3(1, 2, 3, 4, 5)' => 3,
329+
'p4(1, 2, 3, 4, 5)' => 4,
330+
'p5(1, 2, 3, 4, 5)' => 5,
331+
];
332+
333+
foreach ($data as $formula => $result) {
334+
$this->assertEquals($e->evaluate($formula), $result);
335+
}
336+
}
337+
338+
public function testFunctionOrderParameters()
304339
{
305340
$e = new Expression();
306341
$e->suppress_errors = true;
@@ -312,7 +347,6 @@ public function testFormulaWithBrackets()
312347
return max($v1, $v2);
313348
},
314349
];
315-
// $formula = 'max(2,(2+2)*2)';
316350

317351
$data = [
318352
'max(2,(2+2)*2)' => 8,
@@ -334,4 +368,5 @@ public function testFormulaWithBrackets()
334368
$this->assertEquals($e->evaluate($formula), $result);
335369
}
336370
}
371+
337372
}

0 commit comments

Comments
 (0)