summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schlüter <johannes@php.net>2007-08-02 21:55:23 +0000
committerJohannes Schlüter <johannes@php.net>2007-08-02 21:55:23 +0000
commitb3c6a9dffcc3cea84b51da9acd0f0487a2aec871 (patch)
treeacd0be25a1b114868a853c8d865dac7355d64365
parent48d5519378cb4d724ba86c2f90a7d391ff4d3e15 (diff)
downloadphp-git-b3c6a9dffcc3cea84b51da9acd0f0487a2aec871.tar.gz
- Add possibility to call static class members using variables (Etienne Kneuss)
-rw-r--r--NEWS2
-rw-r--r--Zend/zend_language_parser.y12
-rw-r--r--tests/lang/041.phpt20
-rw-r--r--tests/lang/042.phpt19
-rw-r--r--tests/lang/043.phpt19
-rw-r--r--tests/lang/044.phpt21
6 files changed, 93 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 8488800162..a81c6477c6 100644
--- a/NEWS
+++ b/NEWS
@@ -37,6 +37,8 @@ PHP NEWS
- Added PCRE_VERSION constant. (Tony)
- Added ReflectionExtension::info() function to print the phpinfo() block for
an extension. (Johannes)
+- Added possibility to call static class members using variables. (Etienne
+ Kneuss)
- Implemented FR #41884 (ReflectionClass::getDefaultProperties() does not handle
static attributes). (Tony)
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 017c96dc4e..244daae9e5 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -630,6 +630,12 @@ function_call:
| fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' { zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC); zend_do_begin_class_member_function_call(&$1, &$3 TSRMLS_CC); }
function_call_parameter_list
')' { zend_do_end_function_call(NULL, &$$, &$6, 1, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C);}
+ | variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' { zend_do_begin_class_member_function_call(&$1, &$3 TSRMLS_CC); }
+ function_call_parameter_list
+ ')' { zend_do_end_function_call(NULL, &$$, &$6, 1, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C);}
+ | variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' { zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC); zend_do_begin_class_member_function_call(&$1, &$3 TSRMLS_CC); }
+ function_call_parameter_list
+ ')' { zend_do_end_function_call(NULL, &$$, &$6, 1, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C);}
| variable_without_objects '(' { zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC); zend_do_begin_dynamic_function_call(&$1 TSRMLS_CC); }
function_call_parameter_list ')'
{ zend_do_end_function_call(&$1, &$$, &$4, 0, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C);}
@@ -781,8 +787,13 @@ variable_without_objects:
static_member:
fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects { $$ = $3; zend_do_fetch_static_member(&$$, &$1 TSRMLS_CC); }
+ | variable_class_name T_PAAMAYIM_NEKUDOTAYIM variable_without_objects { $$ = $3; zend_do_fetch_static_member(&$$, &$1 TSRMLS_CC); }
+
;
+variable_class_name:
+ reference_variable { zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC); zend_do_fetch_class(&$$, &$1 TSRMLS_CC); }
+;
base_variable_with_function_calls:
base_variable { $$ = $1; }
@@ -907,6 +918,7 @@ isset_variables:
class_constant:
fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT TSRMLS_CC); }
+ | variable_class_name T_PAAMAYIM_NEKUDOTAYIM T_STRING { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT TSRMLS_CC); }
;
%%
diff --git a/tests/lang/041.phpt b/tests/lang/041.phpt
new file mode 100644
index 0000000000..930e912f6d
--- /dev/null
+++ b/tests/lang/041.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Dynamic access of static members
+--FILE--
+<?php
+class A {
+ public static $b = 'foo';
+}
+
+$classname = 'A';
+$wrongClassname = 'B';
+
+echo $classname::$b."\n";
+echo $wrongClassname::$b."\n";
+
+?>
+===DONE===
+--EXPECTF--
+foo
+
+Fatal error: Class 'B' not found in %s041.php on line %d
diff --git a/tests/lang/042.phpt b/tests/lang/042.phpt
new file mode 100644
index 0000000000..4e29d4afba
--- /dev/null
+++ b/tests/lang/042.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Dynamic access of constants
+--FILE--
+<?php
+class A {
+ const B = 'foo';
+}
+
+$classname = 'A';
+$wrongClassname = 'B';
+
+echo $classname::B."\n";
+echo $wrongClassname::B."\n";
+?>
+===DONE===
+--EXPECTF--
+foo
+
+Fatal error: Class 'B' not found in %s042.php on line %d
diff --git a/tests/lang/043.phpt b/tests/lang/043.phpt
new file mode 100644
index 0000000000..d3cd6c163e
--- /dev/null
+++ b/tests/lang/043.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Dynamic call for static methods
+--FILE--
+<?php
+class A {
+ static function foo() { return 'foo'; }
+}
+
+$classname = 'A';
+$wrongClassname = 'B';
+
+echo $classname::foo()."\n";
+echo $wrongClassname::foo()."\n";
+?>
+===DONE===
+--EXPECTF--
+foo
+
+Fatal error: Class 'B' not found in %s043.php on line %d
diff --git a/tests/lang/044.phpt b/tests/lang/044.phpt
new file mode 100644
index 0000000000..1fb48b0b54
--- /dev/null
+++ b/tests/lang/044.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Dynamic call for static methods dynamically named
+--FILE--
+<?php
+class A {
+ static function foo() { return 'foo'; }
+}
+$classname = 'A';
+$wrongClassname = 'B';
+
+$methodname = 'foo';
+
+echo $classname::$methodname()."\n";
+
+echo $wrongClassname::$methodname()."\n";
+?>
+===DONE===
+--EXPECTF--
+foo
+
+Fatal error: Class 'B' not found in %s044.php on line %d