Skip to content

Commit f38583c

Browse files
committed
Remove deprecated use "create_function" in compare rule - FormValidator
Shows error in php 7.2
1 parent 911b715 commit f38583c

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

main/inc/lib/pear/HTML/QuickForm/Rule/Compare.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class HTML_QuickForm_Rule_Compare extends HTML_QuickForm_Rule
5757
* @param string operator name
5858
* @return string operator to use for validation
5959
*/
60-
function _findOperator($name)
60+
public function _findOperator($name)
6161
{
6262
$name = trim($name);
6363
if (empty($name)) {
@@ -79,12 +79,38 @@ function _findOperator($name)
7979
public function validate($values, $operator = null)
8080
{
8181
$operator = $this->_findOperator($operator);
82+
83+
$a = $values[0];
84+
$b = $values[1];
85+
8286
if ('===' != $operator && '!==' != $operator) {
83-
$compareFn = create_function('$a, $b', 'return floatval($a) ' . $operator . ' floatval($b);');
87+
$a = floatval($a);
88+
$b = floatval($b);
8489
} else {
85-
$compareFn = create_function('$a, $b', 'return strval($a) ' . $operator . ' strval($b);');
90+
$a = strval($a);
91+
$b = strval($b);
92+
}
93+
94+
switch ($operator) {
95+
case '===':
96+
return $a === $b;
97+
break;
98+
case '!==':
99+
return $a !== $b;
100+
break;
101+
case '>':
102+
return $a > $b;
103+
break;
104+
case '>=':
105+
return $a >= $b;
106+
break;
107+
case '<':
108+
return $a < $b;
109+
break;
110+
case '<=':
111+
return $a <= $b;
112+
break;
86113
}
87-
return $compareFn($values[0], $values[1]);
88114
}
89115

90116
public function getValidationScript($operator = null)

0 commit comments

Comments
 (0)