]> granicus.if.org Git - php/commitdiff
- Add possibility to call static class members using variables (Etienne Kneuss)
authorJohannes Schlüter <johannes@php.net>
Thu, 2 Aug 2007 21:55:23 +0000 (21:55 +0000)
committerJohannes Schlüter <johannes@php.net>
Thu, 2 Aug 2007 21:55:23 +0000 (21:55 +0000)
NEWS
Zend/zend_language_parser.y
tests/lang/041.phpt [new file with mode: 0644]
tests/lang/042.phpt [new file with mode: 0644]
tests/lang/043.phpt [new file with mode: 0644]
tests/lang/044.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 8488800162f18580c4bfb671e15b0e7ff78631b2..a81c6477c6fa0c3641939ccb4967b95c1929aa93 100644 (file)
--- 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)
index 017c96dc4e6b5789d9edbb8a53ffd5fcba75eea3..244daae9e5f9b866279d82d38e5168c04d21a4e1 100644 (file)
@@ -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 (file)
index 0000000..930e912
--- /dev/null
@@ -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 (file)
index 0000000..4e29d4a
--- /dev/null
@@ -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 (file)
index 0000000..d3cd6c1
--- /dev/null
@@ -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 (file)
index 0000000..1fb48b0
--- /dev/null
@@ -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