colder          Mon Apr  7 10:44:59 2008 UTC

  Added files:                 (Branch: PHP_5_3)
    /php-src/ext/standard/tests/class_object    
                                                forward_static_call_001.phpt 
                                                forward_static_call_002.phpt 
                                                forward_static_call_003.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/standard       basic_functions.c basic_functions.h 
  Log:
  MFH: Implement forward_static_call(_array) to complete LSB. Patch by Mike 
Lively
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.154&r2=1.2027.2.547.2.965.2.155&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.154 
php-src/NEWS:1.2027.2.547.2.965.2.155
--- php-src/NEWS:1.2027.2.547.2.965.2.154       Sat Apr  5 23:50:21 2008
+++ php-src/NEWS        Mon Apr  7 10:44:59 2008
@@ -86,6 +86,7 @@
 - Added PREG_BAD_UTF8_OFFSET_ERROR constant. (Nuno)
 - Added request_order INI variable to control specifically $_REQUEST 
   behavior. (Stas)
+- Added forward_static_call(_array) to complete LSB. (Mike Lively)
 
 - Improved PHP runtime speed and memory usage:
   . Replaced flex based scanner with re2c based scanner. (Marcus, Nuno, Scott)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?r1=1.725.2.31.2.64.2.23&r2=1.725.2.31.2.64.2.24&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.23 
php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.24
--- php-src/ext/standard/basic_functions.c:1.725.2.31.2.64.2.23 Thu Mar 20 
00:52:46 2008
+++ php-src/ext/standard/basic_functions.c      Mon Apr  7 10:44:59 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.23 2008/03/20 00:52:46 dsp Exp $ 
*/
+/* $Id: basic_functions.c,v 1.725.2.31.2.64.2.24 2008/04/07 10:44:59 colder 
Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -811,6 +811,19 @@
 ZEND_END_ARG_INFO()
 
 static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_forward_static_call, 0, 0, 1)
+       ZEND_ARG_INFO(0, function_name)
+       ZEND_ARG_INFO(0, parameter)
+       ZEND_ARG_INFO(0, ...)
+ZEND_END_ARG_INFO()
+
+static
+ZEND_BEGIN_ARG_INFO_EX(arginfo_forward_static_call_array, 0, 0, 2)
+       ZEND_ARG_INFO(0, function_name)
+       ZEND_ARG_INFO(0, parameters) /* ARRAY_INFO(0, parameters, 1) */
+ZEND_END_ARG_INFO()
+
+static
 ZEND_BEGIN_ARG_INFO(arginfo_register_shutdown_function, 0)
        ZEND_ARG_INFO(0, function_name)
 ZEND_END_ARG_INFO()
@@ -3364,6 +3377,8 @@
        PHP_FE(call_user_func_array,                                            
                                        arginfo_call_user_func_array)
        PHP_DEP_FE(call_user_method,                                            
                                        arginfo_call_user_method)
        PHP_DEP_FE(call_user_method_array,                                      
                                        arginfo_call_user_method_array)
+       PHP_FE(forward_static_call,                                             
                                        arginfo_forward_static_call)
+       PHP_FE(forward_static_call_array,                                       
                                        arginfo_forward_static_call_array)
        PHP_FE(serialize,                                                       
                                                        arginfo_serialize)
        PHP_FE(unserialize,                                                     
                                                        arginfo_unserialize)
 
@@ -5228,6 +5243,67 @@
 }
 /* }}} */
 
+/* {{{ proto mixed forward_static_call(mixed function_name [, mixed parmeter] 
[, mixed ...]) U
+   Call a user function which is the first parameter */
+PHP_FUNCTION(forward_static_call)
+{
+       zval *retval_ptr = NULL;
+       zend_fcall_info fci;
+       zend_fcall_info_cache fci_cache;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "f*", &fci, 
&fci_cache, &fci.params, &fci.param_count) == FAILURE) {
+               return;
+       }
+
+       if (!EG(active_op_array)->scope) {
+               zend_error(E_ERROR, "Cannot call forward_static_call() when no 
class scope is active");
+       }
+
+       fci.retval_ptr_ptr = &retval_ptr;
+
+       if (EG(called_scope) &&
+               instanceof_function(EG(called_scope), fci_cache.calling_scope 
TSRMLS_CC)) {
+                       fci_cache.calling_scope = EG(called_scope);
+       }
+       
+       if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && 
fci.retval_ptr_ptr && *fci.retval_ptr_ptr) {
+               COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr);
+       }
+
+       if (fci.params) {
+               efree(fci.params);
+       }
+}
+/* }}} */
+
+/* {{{ proto mixed call_user_func_array(string function_name, array 
parameters) U
+   Call a user function which is the first parameter with the arguments 
contained in array */
+PHP_FUNCTION(forward_static_call_array)
+{
+       zval *params, *retval_ptr = NULL;
+       zend_fcall_info fci;
+       zend_fcall_info_cache fci_cache;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "fa/", &fci, 
&fci_cache, &params) == FAILURE) {
+               return;
+       }
+
+       zend_fcall_info_args(&fci, params TSRMLS_CC);
+       fci.retval_ptr_ptr = &retval_ptr;
+
+       if (EG(called_scope) &&
+               instanceof_function(EG(called_scope), fci_cache.calling_scope 
TSRMLS_CC)) {
+                       fci_cache.calling_scope = EG(called_scope);
+       }
+
+       if (zend_call_function(&fci, &fci_cache TSRMLS_CC) == SUCCESS && 
fci.retval_ptr_ptr && *fci.retval_ptr_ptr) {
+               COPY_PZVAL_TO_ZVAL(*return_value, *fci.retval_ptr_ptr);
+       }
+
+       zend_fcall_info_args_clear(&fci, 1);
+}
+/* }}} */
+
 void user_shutdown_function_dtor(php_shutdown_function_entry 
*shutdown_function_entry) /* {{{ */
 {
        int i;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.h?r1=1.139.2.4.2.6.2.6&r2=1.139.2.4.2.6.2.7&diff_format=u
Index: php-src/ext/standard/basic_functions.h
diff -u php-src/ext/standard/basic_functions.h:1.139.2.4.2.6.2.6 
php-src/ext/standard/basic_functions.h:1.139.2.4.2.6.2.7
--- php-src/ext/standard/basic_functions.h:1.139.2.4.2.6.2.6    Sun Feb  3 
14:45:00 2008
+++ php-src/ext/standard/basic_functions.h      Mon Apr  7 10:44:59 2008
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: basic_functions.h,v 1.139.2.4.2.6.2.6 2008/02/03 14:45:00 helly Exp $ 
*/
+/* $Id: basic_functions.h,v 1.139.2.4.2.6.2.7 2008/04/07 10:44:59 colder Exp $ 
*/
 
 #ifndef BASIC_FUNCTIONS_H
 #define BASIC_FUNCTIONS_H
@@ -84,6 +84,8 @@
 PHP_FUNCTION(call_user_func_array);
 PHP_FUNCTION(call_user_method);
 PHP_FUNCTION(call_user_method_array);
+PHP_FUNCTION(forward_static_call);
+PHP_FUNCTION(forward_static_call_array);
 
 PHP_FUNCTION(register_shutdown_function);
 PHP_FUNCTION(highlight_file);

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/class_object/forward_static_call_001.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/class_object/forward_static_call_001.phpt
+++ php-src/ext/standard/tests/class_object/forward_static_call_001.phpt
--TEST--
forward_static_call() called from outside of a method.
--FILE--
<?php

class A
{
        const NAME = 'A';
        public static function test() {
                echo static::NAME, "\n";
        }
}

class B extends A
{
        const NAME = 'B';

        public static function test() {
                echo self::NAME, "\n";
                forward_static_call(array('parent', 'test'));
        }

        public static function test2() {
                echo self::NAME, "\n";
                forward_static_call(array('self', 'test'));
        }

        public static function test3() {
                echo self::NAME, "\n";
                forward_static_call(array('A', 'test'));
        }
}

class C extends B
{
        const NAME = 'C';

        public static function test()
        {
                echo self::NAME, "\n";
                forward_static_call(array('A', 'test'));
        }
}

A::test();
echo "-\n";
B::test();
echo "-\n";
B::test2();
echo "-\n";
B::test3();
echo "-\n";
C::test();
echo "-\n";
C::test2();
echo "-\n";
C::test3();

?>
===DONE===
--EXPECTF--
A
-
B
B
-
B
B
B
-
B
B
-
C
C
-
B
B
C
-
B
C
===DONE===

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/class_object/forward_static_call_002.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/class_object/forward_static_call_002.phpt
+++ php-src/ext/standard/tests/class_object/forward_static_call_002.phpt
--TEST--
forward_static_call() from outside of a class method.
--FILE--
<?php

class A
{
        public static function test() {
                echo "A\n";
        }
}

function test() {
        forward_static_call(array('A', 'test'));
}

test();

?>
--EXPECTF--
Fatal error: Cannot call forward_static_call() when no class scope is active in 
%s on line %d

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/class_object/forward_static_call_003.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/class_object/forward_static_call_003.phpt
+++ php-src/ext/standard/tests/class_object/forward_static_call_003.phpt
--TEST--
forward_static_call() calling outside of the inheritance chain.
--FILE--
<?php

class A
{
        const NAME = 'A';
        public static function test() {
                echo static::NAME, "\n";
        }
}

class B extends A
{
        const NAME = 'B';

        public static function test() {
                echo self::NAME, "\n";
                forward_static_call(array('parent', 'test'));
        }
}

class C
{
        const NAME = 'C';

        public static function test() {
                echo self::NAME, "\n";
                forward_static_call(array('B', 'test'));
        }
}

A::test();
echo "-\n";
B::test();
echo "-\n";
C::test();

?>
===DONE===
--EXPECTF--
A
-
B
B
-
C
B
B
===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to