From: Johannes Schlüter Date: Thu, 2 Aug 2007 21:55:23 +0000 (+0000) Subject: - Add possibility to call static class members using variables (Etienne Kneuss) X-Git-Tag: php-5.2.4RC1~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3c6a9dffcc3cea84b51da9acd0f0487a2aec871;p=php - Add possibility to call static class members using variables (Etienne Kneuss) --- 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-- + +===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-- + +===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-- + +===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-- + +===DONE=== +--EXPECTF-- +foo + +Fatal error: Class 'B' not found in %s044.php on line %d