jenkins-bot has submitted this change and it was merged.
Change subject: add T_EMPTY operator
......................................................................
add T_EMPTY operator
Time: 397 ms, Memory: 25.00Mb
OK (422 tests, 428 assertions)
Change-Id: Ia7b92a449247e345924f5a364a85726cbeceb09f
---
M includes/Compiler.php
M includes/Runtime.php
M tests/phpunit/includes/RuntimeTest.php
3 files changed, 117 insertions(+), 1 deletion(-)
Approvals:
Pastakhov: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/Compiler.php b/includes/Compiler.php
index 0ac2996..3568bf4 100644
--- a/includes/Compiler.php
+++ b/includes/Compiler.php
@@ -1061,9 +1061,36 @@
$stack = array();
$math = array();
break;
- case T_EMPTY:
case T_ISSET:
case T_UNSET:
+ case T_EMPTY:
+ if( $needOperator ) { throw new
ExceptionFoxway($id, FOXWAY_PHP_SYNTAX_ERROR_UNEXPECTED, $tokenLine); }
+
+ $parentheses[] = $parentFlags;
+ $parentFlags =
FOXWAY_EXPECT_PARENTHES_CLOSE|FOXWAY_EXPECT_LIST_PARAMS|FOXWAY_THIS_IS_FUNCTION;
+
+ array_unshift( $needParams, array(
FOXWAY_STACK_COMMAND=>$id, FOXWAY_STACK_RESULT=>null,
FOXWAY_STACK_PARAM=>array(), FOXWAY_STACK_TOKEN_LINE=>$tokenLine ) );
+
+ if( isset($operator) ) { // Operator
exists. Example: $foo = isset
+ $memOperators[] = &$operator;
// push $operator temporarily without PARAM_2
+ unset($operator);
+ $parentFlags |=
FOXWAY_NEED_RESTORE_OPERATOR;
+ }
+ if( $rightOperators ) { // right
operator was used, example: echo -isset
+ $memOperators[] =
$rightOperators; // push $rightOperators for restore later
+ $rightOperators = array();
+ $parentFlags |=
FOXWAY_NEED_RESTORE_RIGHT_OPERATORS;
+ unset($lastValue);
+ }
+ $parentLevel++;
+
+ ksort($math);
+ $memory[] = array($stack, $math); //
push stack for restore late. Example: echo $a + array
+ $stack = array();
+ $math = array();
+
+ self::getNextToken( $tokens, $index,
$countTokens, $tokenLine, array('(') );
+ break;
case T_LIST:
// @todo
diff --git a/includes/Runtime.php b/includes/Runtime.php
index dab0d0e..f035d57 100644
--- a/includes/Runtime.php
+++ b/includes/Runtime.php
@@ -957,6 +957,40 @@
}
}
break;
+ case T_EMPTY:
+
foreach($value[FOXWAY_STACK_PARAM] as $val) {
+ if(
$val[FOXWAY_STACK_COMMAND] == T_VARIABLE ) { // Example: empty($foo);
+ if(
!isset($thisVariables[ $val[FOXWAY_STACK_PARAM] ]) ) { // undefined variable
+
continue;
+ }
+ $ref =
&$thisVariables[ $val[FOXWAY_STACK_PARAM] ];
+ }else{
+ $ref =
&$val[FOXWAY_STACK_RESULT];
+ }
+ if(
isset($val[FOXWAY_STACK_ARRAY_INDEX]) ) { // Example: $foo[1]
+ $vn =
array_pop( $val[FOXWAY_STACK_ARRAY_INDEX] );
+ foreach(
$val[FOXWAY_STACK_ARRAY_INDEX] as $v ) {
+ if(
!isset($ref[$v]) ) { // undefined array index
+
continue 2;
+ }
+ $ref =
&$ref[$v];
+ }
+ if(
is_string($ref) ) { // @todo it only for compatible with PHP 5.4 on PHP 5.3
@see http://www.php.net/manual/en/function.empty.php Example #2 empty() on
String Offsets
+ if(
(is_string($vn) && $vn == (string)(int)$vn && !empty($ref[$vn]) ||
(!is_string($vn) && !empty($ref[$vn]))) ) {
+
$value[FOXWAY_STACK_RESULT] = false;
+
break 2;
+ }//
index is string
+ }elseif(
!empty($ref[$vn]) ) {
+
$value[FOXWAY_STACK_RESULT] = false;
+ break 2;
+ }
+ }elseif( !empty($ref) )
{ // there is no array index and empty() returns false
+
$value[FOXWAY_STACK_RESULT] = false;
+ break 2;
+ }
+ }
+ $value[FOXWAY_STACK_RESULT] =
true;
+ break;
default:
if( !isset($thisVariables[
$value[FOXWAY_STACK_PARAM][FOXWAY_STACK_PARAM] ]) ) { // Use undefined variable
if(
isset($value[FOXWAY_STACK_ARRAY_INDEX]) ) { // Example: $foo[1]++
diff --git a/tests/phpunit/includes/RuntimeTest.php
b/tests/phpunit/includes/RuntimeTest.php
index 6bfc508..8e9e91c 100644
--- a/tests/phpunit/includes/RuntimeTest.php
+++ b/tests/phpunit/includes/RuntimeTest.php
@@ -2760,4 +2760,59 @@
);
}
+ public function testRun_echo_empty_1() {
+ $this->assertEquals(
+ Runtime::runSource('$a = 0.00; echo (empty($a)?
"empty": "not empty");'),
+ array('empty')
+ );
+ }
+ public function testRun_echo_empty_2() {
+ $this->assertEquals(
+ Runtime::runSource('$b = "0.00"; echo
(empty($b)? "empty": "not empty");'),
+ array('not empty')
+ );
+ }
+ public function testRun_echo_empty_3() {
+ $this->assertEquals(
+ Runtime::runSource('echo
(empty($undefined_variable)? "empty": "not empty");'),
+ array('empty')
+ );
+ }
+ public function testRun_echo_empty_key_string_1() {
+ $this->assertEquals(
+ Runtime::runSource('$expected_array_got_string
= "somestring";
+echo empty($expected_array_got_string[0]) ? "true" : "false";'),
+ array('false')
+ );
+ }
+ public function testRun_echo_empty_key_string_2() {
+ $this->assertEquals(
+ Runtime::runSource('echo
empty($expected_array_got_string["0"]) ? "true" : "false";'),
+ array('false')
+ );
+ }
+ public function testRun_echo_empty_key_string_3() {
+ $this->assertEquals(
+ Runtime::runSource('echo
empty($expected_array_got_string[0.5]) ? "true" : "false";'),
+ array('false')
+ );
+ }
+ public function testRun_echo_empty_key_string_4() { //PHP 5.4 changes
how isset() behaves when passed string offsets.
+ $this->assertEquals(
+ Runtime::runSource('echo
empty($expected_array_got_string["some_key"]) ? "true" : "false";'),
+ array('true')
+ );
+ }
+ public function testRun_echo_empty_key_string_5() { //PHP 5.4 changes
how isset() behaves when passed string offsets.
+ $this->assertEquals(
+ Runtime::runSource('echo
empty($expected_array_got_string["0.5"]) ? "true" : "false";'),
+ array('true')
+ );
+ }
+ public function testRun_echo_empty_key_string_6() { //PHP 5.4 changes
how isset() behaves when passed string offsets.
+ $this->assertEquals(
+ Runtime::runSource('echo
empty($expected_array_got_string["0 Mostel"]) ? "true" : "false";'),
+ array('true')
+ );
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/93923
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia7b92a449247e345924f5a364a85726cbeceb09f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: develop
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: Pastakhov <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits