Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: php/php-src
base: master
...
head fork: ircmaxell/php-src
compare: static_operation_parsing
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
12 Zend/tests/class_properties_dynamic-failure.phpt
@@ -0,0 +1,12 @@
+--TEST--
+Class Property Expressions Failure
+--FILE--
+<?php
+class Foo {
+ const BAR = 1 << 0;
+ const BAZ = 1 << 1;
+ public $bar = self::BAR | self::BAZ;
+}
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected '|', expecting ',' or ';' in %s/class_properties_dynamic-failure.php on line %d
View
20 Zend/tests/class_properties_dynamic.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Class Property Expressions
+--FILE--
+<?php
+class Foo {
+ public $b1 = 1 + 1;
+ public $b2 = 1 << 2;
+ public $b3 = "foo " . " bar " . " baz";
+}
+$f = new Foo;
+var_dump(
+ $f->b1,
+ $f->b2,
+ $f->b3
+);
+?>
+--EXPECT--
+int(2)
+int(4)
+string(13) "foo bar baz"
View
9 Zend/tests/constants/constant-expressions-failure.phpt
@@ -0,0 +1,9 @@
+--TEST--
+Constant Expressions Failure
+--FILE--
+<?php
+const FOO = 1;
+const BAR = FOO | 1;
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected '|', expecting ',' or ';' in %s/constant-expressions-failure.php on line %d
View
46 Zend/tests/constants/constant-expressions.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Constant Expressions
+--FILE--
+<?php
+const T_1 = 1 << 1;
+const T_2 = 1 / 2;
+const T_3 = 1.5 + 1.5;
+const T_4 = "foo" . "bar";
+const T_5 = (1.5 + 1.5) * 2;
+const T_6 = "foo" . 2 . 3 . 4.0;
+const T_7 = __LINE__;
+const T_8 = <<<ENDOFSTRING
+This is a test string
+ENDOFSTRING;
+const T_9 = ~-1;
+
+// Test order of operations
+const T_10 = 1 + 2 * 3;
+
+// Test for memory leaks
+const T_11 = "1" + 2 + "3";
+
+var_dump(T_1);
+var_dump(T_2);
+var_dump(T_3);
+var_dump(T_4);
+var_dump(T_5);
+var_dump(T_6);
+var_dump(T_7);
+var_dump(T_8);
+var_dump(T_9);
+var_dump(T_10);
+var_dump(T_11);
+?>
+--EXPECT--
+int(2)
+float(0.5)
+float(3)
+string(6) "foobar"
+float(6)
+string(6) "foo234"
+int(8)
+string(21) "This is a test string"
+int(0)
+int(7)
+int(6)
View
14 Zend/tests/function_arguments_003.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Function Argument Parsing #003
+--FILE--
+<?php
+function t1($a = 1 + 1, $b = 1 << 2, $c = "foo" . "bar") {
+ var_dump($a, $b, $c);
+}
+
+t1();
+?>
+--EXPECT--
+int(2)
+int(4)
+string(6) "foobar"
View
20 Zend/tests/static_variable.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Static Variable Expressions
+--FILE--
+<?php
+function foo() {
+ static $a = 1 + 1;
+ static $b = [ 1 + 1, 1 << 2 ];
+ var_dump($a, $b);
+}
+
+foo();
+?>
+--EXPECT--
+int(2)
+array(2) {
+ [0]=>
+ int(2)
+ [1]=>
+ int(4)
+}
View
28 Zend/zend_language_parser.y
@@ -943,19 +943,41 @@ common_scalar:
static_scalar: /* compile-time evaluated scalars */
- common_scalar { $$ = $1; }
+ static_scalar_value { $$ = $1; }
| static_class_name_scalar { $$ = $1; }
| namespace_name { zend_do_fetch_constant(&$$, NULL, &$1, ZEND_CT, 1 TSRMLS_CC); }
| T_NAMESPACE T_NS_SEPARATOR namespace_name { $$.op_type = IS_CONST; ZVAL_EMPTY_STRING(&$$.u.constant); zend_do_build_namespace_name(&$$, &$$, &$3 TSRMLS_CC); $3 = $$; zend_do_fetch_constant(&$$, NULL, &$3, ZEND_CT, 0 TSRMLS_CC); }
| T_NS_SEPARATOR namespace_name { char *tmp = estrndup(Z_STRVAL($2.u.constant), Z_STRLEN($2.u.constant)+1); memcpy(&(tmp[1]), Z_STRVAL($2.u.constant), Z_STRLEN($2.u.constant)+1); tmp[0] = '\\'; efree(Z_STRVAL($2.u.constant)); Z_STRVAL($2.u.constant) = tmp; ++Z_STRLEN($2.u.constant); zend_do_fetch_constant(&$$, NULL, &$2, ZEND_CT, 0 TSRMLS_CC); }
- | '+' static_scalar { ZVAL_LONG(&$1.u.constant, 0); add_function(&$2.u.constant, &$1.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
- | '-' static_scalar { ZVAL_LONG(&$1.u.constant, 0); sub_function(&$2.u.constant, &$1.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
| T_ARRAY '(' static_array_pair_list ')' { $$ = $3; Z_TYPE($$.u.constant) = IS_CONSTANT_ARRAY; }
| '[' static_array_pair_list ']' { $$ = $2; Z_TYPE($$.u.constant) = IS_CONSTANT_ARRAY; }
| static_class_constant { $$ = $1; }
| T_CLASS_C { $$ = $1; }
;
+static_scalar_value:
+ common_scalar { $$ = $1; }
+ | '+' static_scalar_value { ZVAL_LONG(&$1.u.constant, 0); add_function(&$2.u.constant, &$1.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
+ | '-' static_scalar_value { ZVAL_LONG(&$1.u.constant, 0); sub_function(&$2.u.constant, &$1.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
+ | '(' static_scalar_value ')' { $$ = $2; }
+ | static_operation { $$ = $1; }
+;
+
+static_operation:
+ static_scalar_value '+' static_scalar_value { add_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '-' static_scalar_value { sub_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '*' static_scalar_value { mul_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '/' static_scalar_value { div_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '%' static_scalar_value { mod_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | '!' static_scalar_value { boolean_not_function(&$2.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
+ | '~' static_scalar_value { bitwise_not_function(&$2.u.constant, &$2.u.constant TSRMLS_CC); $$ = $2; }
+ | static_scalar_value '|' static_scalar_value { bitwise_or_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '&' static_scalar_value { bitwise_and_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '^' static_scalar_value { bitwise_xor_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value T_SL static_scalar_value { shift_left_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value T_SR static_scalar_value { shift_right_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+ | static_scalar_value '.' static_scalar_value { concat_function(&$1.u.constant, &$1.u.constant, &$3.u.constant TSRMLS_CC); zval_dtor(&$3.u.constant); $$ = $1; }
+;
+
static_class_constant:
class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_CT, 0 TSRMLS_CC); }
;

No commit comments for this range

Something went wrong with that request. Please try again.