cvs: ZendEngine2 / zend.h zend_API.c zend_API.h zend_compile.c zend_compile.h zend_execute_API.c zend_interfaces.c zend_object_handlers.c
zend_vm_def.h zend_vm_execute.h /tests call_static.phpt object_handlers.phpt

From: Date: Sat, 21 Jul 2007 05:27:07 +0000
Subject: cvs: ZendEngine2 / zend.h zend_API.c zend_API.h zend_compile.c zend_compile.h zend_execute_API.c zend_interfaces.c zend_object_handlers.c
zend_vm_def.h zend_vm_execute.h /tests call_static.phpt object_handlers.phpt
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-5914@lists.php.net to get a copy of this message
pollita Sat Jul 21 05:27:07 2007 UTC Added files: /ZendEngine2/tests call_static.phpt Modified files: /ZendEngine2/tests object_handlers.phpt /ZendEngine2 zend.h zend_API.c zend_API.h zend_compile.c zend_compile.h zend_execute_API.c zend_interfaces.c zend_object_handlers.c zend_vm_def.h zend_vm_execute.h Log: Add support got zend_class_entry->get_static_method() and matching __callStatic() userspace method @doc

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/object_handlers.phpt?r1=1.2&r2=1.3&diff_format=u Index: ZendEngine2/tests/object_handlers.phpt diff -u ZendEngine2/tests/object_handlers.phpt:1.2 ZendEngine2/tests/object_handlers.phpt:1.3 --- ZendEngine2/tests/object_handlers.phpt:1.2 Fri Jun 3 11:16:19 2005 +++ ZendEngine2/tests/object_handlers.phpt Sat Jul 21 05:27:06 2007 @@ -1,171 +1,177 @@ ---TEST-- -Magic object handlers segfaults and memory errors ---FILE-- -<?php -function f($x) { - return $x; -} - -class foo implements ArrayAccess { - function __get($property) { - $GLOBALS["y"] = $property; - } - function __set($property, $value) { - $GLOBALS["y"] = $property; - } - function __call($func, $args) { - $GLOBALS["y"] = $func; - } - function offsetGet($index) { - $GLOBALS["y"] = $index; - } - function offsetSet($index, $newval) { - $GLOBALS["y"] = $index; - } - function offsetExists($index) { - $GLOBALS["y"] = $index; - } - function offsetUnset($index) { - $GLOBALS["y"] = $index; - } -} - -$x = new foo(); -$y = null; - -// IS_CONST -$z = $x->const_get; -echo $y,"\n"; -$x->const_set = 1; -echo $y,"\n"; -$x->const_call(); -echo $y,"\n"; -$z = $x["const_dim_get"]; -echo $y,"\n"; -$x["const_dim_set"] = 1; -echo $y,"\n"; -isset($x["const_dim_isset"]); -echo $y,"\n"; -unset($x["const_dim_unset"]); -echo $y,"\n"; - -// IS_CONST + conversion -$z = $x->{1}; -echo $y,"\n"; -$x->{2} = 1; -echo $y,"\n"; - -// IS_TMP_VAR -$c = "tmp"; -$z = $x->{$c."_get"}; -echo $y,"\n"; -$x->{$c."_set"} = 1; -echo $y,"\n"; -$x->{$c."_call"}(); -echo $y,"\n"; -$z = $x[$c."_dim_get"]; -echo $y,"\n"; -$x[$c."_dim_set"] = 1; -echo $y,"\n"; -isset($x[$c."_dim_isset"]); -echo $y,"\n"; -unset($x[$c."_dim_unset"]); -echo $y,"\n"; - -// IS_TMP_VAR + conversion -$c = 0; -$z = $x->{$c+3}; -echo $y,"\n"; -$x->{$c+4} = 1; -echo $y,"\n"; - -// IS_CV -$c = "cv_get"; -$z = $x->{$c}; -echo $y,"\n"; -$c = "cv_set"; -$x->{$c} = 1; -echo $y,"\n"; -$c = "cv_call"; -$x->{$c}(); -echo $y,"\n"; -$c = "cv_dim_get"; -$z = $x[$c]; -echo $y,"\n"; -$c = "cv_dim_set"; -$x[$c] = 1; -echo $y,"\n"; -$c = "cv_dim_isset"; -isset($x[$c]); -echo $y,"\n"; -$c = "cv_dim_unset"; -unset($x[$c]); -echo $y,"\n"; - -// IS_CV + conversion -$c = 5; -$z = $x->{$c}; -echo $y,"\n"; -$c = 6; -$x->{$c} = 1; -echo $y,"\n"; - -// IS_VAR -$z = $x->{f("var_get")}; -echo $y,"\n"; -$x->{f("var_set")} = 1; -echo $y,"\n"; -$x->{f("var_call")}(); -echo $y,"\n"; -$z = $x[f("var_dim_get")]; -echo $y,"\n"; -$x[f("var_dim_set")] = 1; -echo $y,"\n"; -isset($x[f("var_dim_isset")]); -echo $y,"\n"; -unset($x[f("var_dim_unset")]); -echo $y,"\n"; - -// IS_VAR + conversion -$z = $x->{f(7)}; -echo $y,"\n"; -$x->{f(8)} = 1; -echo $y,"\n"; -?> ---EXPECT-- -const_get -const_set -const_call -const_dim_get -const_dim_set -const_dim_isset -const_dim_unset -1 -2 -tmp_get -tmp_set -tmp_call -tmp_dim_get -tmp_dim_set -tmp_dim_isset -tmp_dim_unset -3 -4 -cv_get -cv_set -cv_call -cv_dim_get -cv_dim_set -cv_dim_isset -cv_dim_unset -5 -6 -var_get -var_set -var_call -var_dim_get -var_dim_set -var_dim_isset -var_dim_unset -7 -8 +--TEST-- +Magic object handlers segfaults and memory errors +--FILE-- +<?php +function f($x) { + return $x; +} + +class foo implements ArrayAccess { + function __get($property) { + $GLOBALS["y"] = $property; + } + function __set($property, $value) { + $GLOBALS["y"] = $property; + } + function __call($func, $args) { + $GLOBALS["y"] = $func; + } + static function __callStatic($func, $args) { + $GLOBALS["y"] = $func; + } + function offsetGet($index) { + $GLOBALS["y"] = $index; + } + function offsetSet($index, $newval) { + $GLOBALS["y"] = $index; + } + function offsetExists($index) { + $GLOBALS["y"] = $index; + } + function offsetUnset($index) { + $GLOBALS["y"] = $index; + } +} + +$x = new foo(); +$y = null; + +// IS_CONST +$z = $x->const_get; +echo $y,"\n"; +$x->const_set = 1; +echo $y,"\n"; +$x->const_call(); +echo $y,"\n"; +foo::const_callstatic(); +echo $y,"\n"; +$z = $x["const_dim_get"]; +echo $y,"\n"; +$x["const_dim_set"] = 1; +echo $y,"\n"; +isset($x["const_dim_isset"]); +echo $y,"\n"; +unset($x["const_dim_unset"]); +echo $y,"\n"; + +// IS_CONST + conversion +$z = $x->{1}; +echo $y,"\n"; +$x->{2} = 1; +echo $y,"\n"; + +// IS_TMP_VAR +$c = "tmp"; +$z = $x->{$c."_get"}; +echo $y,"\n"; +$x->{$c."_set"} = 1; +echo $y,"\n"; +$x->{$c."_call"}(); +echo $y,"\n"; +$z = $x[$c."_dim_get"]; +echo $y,"\n"; +$x[$c."_dim_set"] = 1; +echo $y,"\n"; +isset($x[$c."_dim_isset"]); +echo $y,"\n"; +unset($x[$c."_dim_unset"]); +echo $y,"\n"; + +// IS_TMP_VAR + conversion +$c = 0; +$z = $x->{$c+3}; +echo $y,"\n"; +$x->{$c+4} = 1; +echo $y,"\n"; + +// IS_CV +$c = "cv_get"; +$z = $x->{$c}; +echo $y,"\n"; +$c = "cv_set"; +$x->{$c} = 1; +echo $y,"\n"; +$c = "cv_call"; +$x->{$c}(); +echo $y,"\n"; +$c = "cv_dim_get"; +$z = $x[$c]; +echo $y,"\n"; +$c = "cv_dim_set"; +$x[$c] = 1; +echo $y,"\n"; +$c = "cv_dim_isset"; +isset($x[$c]); +echo $y,"\n"; +$c = "cv_dim_unset"; +unset($x[$c]); +echo $y,"\n"; + +// IS_CV + conversion +$c = 5; +$z = $x->{$c}; +echo $y,"\n"; +$c = 6; +$x->{$c} = 1; +echo $y,"\n"; + +// IS_VAR +$z = $x->{f("var_get")}; +echo $y,"\n"; +$x->{f("var_set")} = 1; +echo $y,"\n"; +$x->{f("var_call")}(); +echo $y,"\n"; +$z = $x[f("var_dim_get")]; +echo $y,"\n"; +$x[f("var_dim_set")] = 1; +echo $y,"\n"; +isset($x[f("var_dim_isset")]); +echo $y,"\n"; +unset($x[f("var_dim_unset")]); +echo $y,"\n"; + +// IS_VAR + conversion +$z = $x->{f(7)}; +echo $y,"\n"; +$x->{f(8)} = 1; +echo $y,"\n"; +?> +--EXPECT-- +const_get +const_set +const_call +const_callstatic +const_dim_get +const_dim_set +const_dim_isset +const_dim_unset +1 +2 +tmp_get +tmp_set +tmp_call +tmp_dim_get +tmp_dim_set +tmp_dim_isset +tmp_dim_unset +3 +4 +cv_get +cv_set +cv_call +cv_dim_get +cv_dim_set +cv_dim_isset +cv_dim_unset +5 +6 +var_get +var_set +var_call +var_dim_get +var_dim_set +var_dim_isset +var_dim_unset +7 +8 http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.h?r1=1.334&r2=1.335&diff_format=u Index: ZendEngine2/zend.h diff -u ZendEngine2/zend.h:1.334 ZendEngine2/zend.h:1.335 --- ZendEngine2/zend.h:1.334 Thu Apr 26 19:08:24 2007 +++ ZendEngine2/zend.h Sat Jul 21 05:27:06 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend.h,v 1.334 2007/04/26 19:08:24 tony2001 Exp $ */ +/* $Id: zend.h,v 1.335 2007/07/21 05:27:06 pollita Exp $ */ #ifndef ZEND_H #define ZEND_H @@ -378,6 +378,7 @@ union _zend_function *__unset; union _zend_function *__isset; union _zend_function *__call; + union _zend_function *__callstatic; union _zend_function *__tostring; union _zend_function *serialize_func; union _zend_function *unserialize_func; @@ -388,6 +389,7 @@ zend_object_value (*create_object)(zend_class_entry *class_type TSRMLS_DC); zend_object_iterator *(*get_iterator)(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC); int (*interface_gets_implemented)(zend_class_entry *iface, zend_class_entry *class_type TSRMLS_DC); /* a class implements this interface */ + union _zend_function *(*get_static_method)(zend_class_entry *ce, zstr method, int method_len TSRMLS_DC); /* serializer callbacks */ int (*serialize)(zval *object, int *type, zstr *buffer, zend_uint *buf_len, zend_serialize_data *data TSRMLS_DC); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.c?r1=1.440&r2=1.441&diff_format=u Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.440 ZendEngine2/zend_API.c:1.441 --- ZendEngine2/zend_API.c:1.440 Sat Jul 14 08:51:17 2007 +++ ZendEngine2/zend_API.c Sat Jul 21 05:27:06 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.440 2007/07/14 08:51:17 dmitry Exp $ */ +/* $Id: zend_API.c,v 1.441 2007/07/21 05:27:06 pollita Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -2026,6 +2026,9 @@ } else if (lcname_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && ZEND_U_EQUAL(utype, lcname, lcname_len, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1) && fptr->common.num_args != 2) { zend_error(error_type, "Method %v::%s() must take exactly 2 arguments", ce->name, ZEND_CALL_FUNC_NAME); + } else if (lcname_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME) - 1 && + ZEND_U_EQUAL(utype, lcname, lcname_len, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && fptr->common.num_args != 2) { + zend_error(error_type, "Method %v::%s() must take exactly 2 arguments", ce->name, ZEND_CALLSTATIC_FUNC_NAME); } else if (lcname_len == sizeof(ZEND_TOSTRING_FUNC_NAME) - 1 && ZEND_U_EQUAL(utype, lcname, lcname_len, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && fptr->common.num_args != 0) { zend_error(error_type, "Method %v::%s() cannot take arguments", ce->name, ZEND_TOSTRING_FUNC_NAME); @@ -2043,7 +2046,7 @@ int count=0, unload=0; HashTable *target_function_table = function_table; int error_type; - zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__tostring = NULL; + zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__callstatic = NULL, *__tostring = NULL; char *lowercase_name; int fname_len; zstr lc_class_name = NULL_ZSTR; @@ -2186,6 +2189,8 @@ clone = reg_function; } else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) { __call = reg_function; + } else if ((fname_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME))) { + __callstatic = reg_function; } else if ((fname_len == sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME))) { __tostring = reg_function; } else if ((fname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) { @@ -2226,6 +2231,7 @@ scope->destructor = dtor; scope->clone = clone; scope->__call = __call; + scope->__callstatic = __callstatic; scope->__tostring = __tostring; scope->__get = __get; scope->__set = __set; @@ -2258,6 +2264,12 @@ } __call->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC; } + if (__callstatic) { + if (!(__callstatic->common.fn_flags & ZEND_ACC_STATIC)) { + zend_error(error_type, "Method %v::%v() must be static", scope->name, __callstatic->common.function_name); + } + __callstatic->common.fn_flags |= ZEND_ACC_STATIC; + } if (__tostring) { if (__tostring->common.fn_flags & ZEND_ACC_STATIC) { zend_error(error_type, "Method %v::%v() cannot be static", scope->name, __tostring->common.function_name); @@ -2662,6 +2674,10 @@ retval = (*ce_ptr)->__call != NULL; *fptr_ptr = (*ce_ptr)->__call; } + if (!*zobj_ptr_ptr && *ce_ptr && (*ce_ptr)->__callstatic) { + retval = 1; + *fptr_ptr = (*ce_ptr)->__callstatic; + } } else { *fptr_ptr = fptr; if (*ce_ptr) { @@ -2951,7 +2967,8 @@ fci->no_separation = 1; fci->symbol_table = NULL; - if (ZEND_U_EQUAL(ZEND_STR_TYPE, func->common.function_name, USTR_LEN(func->common.function_name), ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1)) { + if (ZEND_U_CASE_EQUAL(ZEND_STR_TYPE, func->common.function_name, USTR_LEN(func->common.function_name), ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1) || + ZEND_U_CASE_EQUAL(ZEND_STR_TYPE, func->common.function_name, USTR_LEN(func->common.function_name), ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1)) { fcc->initialized = 0; fcc->function_handler = NULL; fcc->calling_scope = NULL; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_API.h?r1=1.289&r2=1.290&diff_format=u Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.289 ZendEngine2/zend_API.h:1.290 --- ZendEngine2/zend_API.h:1.289 Wed Jul 11 15:17:41 2007 +++ ZendEngine2/zend_API.h Sat Jul 21 05:27:06 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.289 2007/07/11 15:17:41 dmitry Exp $ */ +/* $Id: zend_API.h,v 1.290 2007/07/21 05:27:06 pollita Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -148,7 +148,9 @@ class_container.unserialize = NULL; \ class_container.create_object = NULL; \ class_container.interface_gets_implemented = NULL; \ + class_container.get_static_method = NULL; \ class_container.__call = handle_fcall; \ + class_container.__callstatic = NULL; \ class_container.__tostring = NULL; \ class_container.__get = handle_propget; \ class_container.__set = handle_propset; \ http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.c?r1=1.755&r2=1.756&diff_format=u Index: ZendEngine2/zend_compile.c diff -u ZendEngine2/zend_compile.c:1.755 ZendEngine2/zend_compile.c:1.756 --- ZendEngine2/zend_compile.c:1.755 Fri Jul 13 08:19:51 2007 +++ ZendEngine2/zend_compile.c Sat Jul 21 05:27:06 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.c,v 1.755 2007/07/13 08:19:51 dmitry Exp $ */ +/* $Id: zend_compile.c,v 1.756 2007/07/21 05:27:06 pollita Exp $ */ #include <zend_language_parser.h> #include "zend.h" @@ -1222,6 +1222,8 @@ CG(active_class_entry)->clone = (zend_function *) CG(active_op_array); } else if ((lcname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && (ZEND_U_EQUAL(Z_TYPE(function_name->u.constant), lcname, lcname_len, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)-1))) { CG(active_class_entry)->__call = (zend_function *) CG(active_op_array); + } else if ((lcname_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1) && (ZEND_U_EQUAL(Z_TYPE(function_name->u.constant), lcname, lcname_len, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1))) { + CG(active_class_entry)->__callstatic = (zend_function *) CG(active_op_array); } else if ((lcname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && (ZEND_U_EQUAL(Z_TYPE(function_name->u.constant), lcname, lcname_len, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)-1))) { CG(active_class_entry)->__get = (zend_function *) CG(active_op_array); } else if ((lcname_len == sizeof(ZEND_SET_FUNC_NAME)-1) && (ZEND_U_EQUAL(Z_TYPE(function_name->u.constant), lcname, lcname_len, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)-1))) { @@ -2185,6 +2187,9 @@ if (!ce->__call) { ce->__call = ce->parent->__call; } + if (!ce->__callstatic) { + ce->__callstatic = ce->parent->__callstatic; + } if (!ce->__tostring) { ce->__tostring = ce->parent->__tostring; } @@ -4670,11 +4675,13 @@ ce->__unset = NULL; ce->__isset = NULL; ce->__call = NULL; + ce->__callstatic = NULL; ce->__tostring = NULL; ce->create_object = NULL; ce->get_iterator = NULL; ce->iterator_funcs.funcs = NULL; ce->interface_gets_implemented = NULL; + ce->get_static_method = NULL; ce->parent = NULL; ce->num_interfaces = 0; ce->interfaces = NULL; http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_compile.h?r1=1.360&r2=1.361&diff_format=u Index: ZendEngine2/zend_compile.h diff -u ZendEngine2/zend_compile.h:1.360 ZendEngine2/zend_compile.h:1.361 --- ZendEngine2/zend_compile.h:1.360 Thu Jul 12 09:23:48 2007 +++ ZendEngine2/zend_compile.h Sat Jul 21 05:27:07 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_compile.h,v 1.360 2007/07/12 09:23:48 dmitry Exp $ */ +/* $Id: zend_compile.h,v 1.361 2007/07/21 05:27:07 pollita Exp $ */ #ifndef ZEND_COMPILE_H #define ZEND_COMPILE_H @@ -742,6 +742,7 @@ #define ZEND_UNSET_FUNC_NAME "__unset" #define ZEND_ISSET_FUNC_NAME "__isset" #define ZEND_CALL_FUNC_NAME "__call" +#define ZEND_CALLSTATIC_FUNC_NAME "__callstatic" #define ZEND_TOSTRING_FUNC_NAME "__tostring" #define ZEND_AUTOLOAD_FUNC_NAME "__autoload" http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_execute_API.c?r1=1.408&r2=1.409&diff_format=u Index: ZendEngine2/zend_execute_API.c diff -u ZendEngine2/zend_execute_API.c:1.408 ZendEngine2/zend_execute_API.c:1.409 --- ZendEngine2/zend_execute_API.c:1.408 Sat Jul 21 00:34:41 2007 +++ ZendEngine2/zend_execute_API.c Sat Jul 21 05:27:07 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_execute_API.c,v 1.408 2007/07/21 00:34:41 jani Exp $ */ +/* $Id: zend_execute_API.c,v 1.409 2007/07/21 05:27:07 pollita Exp $ */ #include <stdio.h> #include <signal.h> @@ -882,9 +882,13 @@ unsigned int lcname_len; zstr lcname = zend_u_str_case_fold(Z_TYPE_P(fci->function_name), fname, fname_len, 1, &lcname_len); - EX(function_state).function = - zend_std_get_static_method(calling_scope, lcname, lcname_len TSRMLS_CC); + if (calling_scope->get_static_method) { + EX(function_state).function = calling_scope->get_static_method(calling_scope, lcname, lcname_len TSRMLS_CC); + } else { + EX(function_state).function = zend_std_get_static_method(calling_scope, lcname, lcname_len TSRMLS_CC); + } efree(lcname.v); + if (check_scope_or_static && EX(function_state).function && !(EX(function_state).function->common.fn_flags & ZEND_ACC_STATIC) && !instanceof_function(check_scope_or_static, calling_scope TSRMLS_CC)) { http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_interfaces.c?r1=1.63&r2=1.64&diff_format=u Index: ZendEngine2/zend_interfaces.c diff -u ZendEngine2/zend_interfaces.c:1.63 ZendEngine2/zend_interfaces.c:1.64 --- ZendEngine2/zend_interfaces.c:1.63 Wed May 30 16:31:47 2007 +++ ZendEngine2/zend_interfaces.c Sat Jul 21 05:27:07 2007 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_interfaces.c,v 1.63 2007/05/30 16:31:47 tony2001 Exp $ */ +/* $Id: zend_interfaces.c,v 1.64 2007/07/21 05:27:07 pollita Exp $ */ #include "zend.h" #include "zend_API.h" @@ -57,7 +57,7 @@ if (!fn_proxy && !obj_ce) { /* no interest in caching and no information already present that is * needed later inside zend_call_function. */ - ZVAL_ZSTRL(&z_fname, function_name_type, function_name, function_name_len, 1); + ZVAL_ZSTRL(&z_fname, function_name_type, function_name, function_name_len, ZSTR_DUPLICATE); fci.function_table = !object_pp ? EG(function_table) : NULL; result = zend_call_function(&fci, NULL TSRMLS_CC); zval_dtor(&z_fname); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_object_handlers.c?r1=1.186&r2=1.187&diff_format=u Index: ZendEngine2/zend_object_handlers.c diff -u ZendEngine2/zend_object_handlers.c:1.186 ZendEngine2/zend_object_handlers.c:1.187 --- ZendEngine2/zend_object_handlers.c:1.186 Thu Jul 12 10:32:26 2007 +++ ZendEngine2/zend_object_handlers.c Sat Jul 21 05:27:07 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_object_handlers.c,v 1.186 2007/07/12 10:32:26 dmitry Exp $ */ +/* $Id: zend_object_handlers.c,v 1.187 2007/07/21 05:27:07 pollita Exp $ */ #include "zend.h" #include "zend_globals.h" @@ -858,21 +858,88 @@ } /* }}} */ -/* This is not (yet?) in the API, but it belongs in the built-in objects callbacks */ +ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ +{ + zend_internal_function *func = (zend_internal_function *)EG(function_state_ptr)->function; + zval *method_name_ptr, *method_args_ptr; + zval *method_result_ptr = NULL; + zend_class_entry *ce = EG(scope); + + ALLOC_ZVAL(method_args_ptr); + INIT_PZVAL(method_args_ptr); + array_init(method_args_ptr); + + if (zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE) { + zval_dtor(method_args_ptr); + zend_error(E_ERROR, "Cannot get arguments for " ZEND_CALLSTATIC_FUNC_NAME); + RETURN_FALSE; + } + + ALLOC_ZVAL(method_name_ptr); + INIT_PZVAL(method_name_ptr); + ZVAL_TEXT(method_name_ptr, func->function_name, 0); /* no dup - it's a copy */ + + /* __callStatic handler is called with two arguments: + method name + array of method parameters + */ + zend_call_method_with_2_params(NULL, ce, &ce->__callstatic, ZEND_CALLSTATIC_FUNC_NAME, &method_result_ptr, method_name_ptr, method_args_ptr); + + if (method_result_ptr) { + if (method_result_ptr->is_ref || method_result_ptr->refcount > 1) { + RETVAL_ZVAL(method_result_ptr, 1, 1); + } else { + RETVAL_ZVAL(method_result_ptr, 0, 1); + } + } + + /* now destruct all auxiliaries */ + zval_ptr_dtor(&method_args_ptr); + zval_ptr_dtor(&method_name_ptr); + + /* destruct the function also, then - we have allocated it in get_method */ + efree(func); +} +/* }}} */ + + ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zstr function_name_strval, int function_name_strlen TSRMLS_DC) /* {{{ */ { zend_function *fbc; /* FIXME: type is default */ zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING; - if (zend_u_hash_find(&ce->function_table, type, function_name_strval, function_name_strlen+1, (void **) &fbc)==FAILURE) { - zstr class_name = ce->name; + if (zend_u_hash_find(&ce->function_table, type, function_name_strval, function_name_strlen + 1, (void **) &fbc)==FAILURE) { + if (ce->__callstatic) { + zend_internal_function *callstatic_user_call = emalloc(sizeof(zend_internal_function)); + callstatic_user_call->type = ZEND_INTERNAL_FUNCTION; + callstatic_user_call->module = ce->module; + callstatic_user_call->handler = zend_std_callstatic_user_call; + callstatic_user_call->arg_info = NULL; + callstatic_user_call->num_args = 0; + callstatic_user_call->scope = ce; + callstatic_user_call->fn_flags = ZEND_ACC_STATIC | ZEND_ACC_PUBLIC; + + if (UG(unicode)) { + callstatic_user_call->function_name.u = eustrndup(function_name_strval.u, function_name_strlen); + } else { + callstatic_user_call->function_name.s = estrndup(function_name_strval.s, function_name_strlen); + } + + callstatic_user_call->pass_rest_by_reference = 0; + callstatic_user_call->return_reference = ZEND_RETURN_VALUE; + + return (zend_function *)callstatic_user_call; + } else { + zstr class_name = ce->name; - if (!class_name.v) { - class_name.u = EMPTY_STR; + if (!class_name.v) { + class_name.u = EMPTY_STR; + } + zend_error(E_ERROR, "Call to undefined method %R::%R()", type, class_name, type, function_name_strval); } - zend_error(E_ERROR, "Call to undefined method %R::%R()", type, class_name, type, function_name_strval); } + #if MBO_0 /* right now this function is used for non static method lookup too */ /* Is the function static */ http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_def.h?r1=1.172&r2=1.173&diff_format=u Index: ZendEngine2/zend_vm_def.h diff -u ZendEngine2/zend_vm_def.h:1.172 ZendEngine2/zend_vm_def.h:1.173 --- ZendEngine2/zend_vm_def.h:1.172 Sat Jul 14 08:51:17 2007 +++ ZendEngine2/zend_vm_def.h Sat Jul 21 05:27:07 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_vm_def.h,v 1.172 2007/07/14 08:51:17 dmitry Exp $ */ +/* $Id: zend_vm_def.h,v 1.173 2007/07/21 05:27:07 pollita Exp $ */ /* If you change this file, please regenerate the zend_vm_execute.h and * zend_vm_opcodes.h files by running: @@ -1848,7 +1848,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_vm_execute.h?r1=1.176&r2=1.177&diff_format=u Index: ZendEngine2/zend_vm_execute.h diff -u ZendEngine2/zend_vm_execute.h:1.176 ZendEngine2/zend_vm_execute.h:1.177 --- ZendEngine2/zend_vm_execute.h:1.176 Sat Jul 21 00:34:41 2007 +++ ZendEngine2/zend_vm_execute.h Sat Jul 21 05:27:07 2007 @@ -2602,7 +2602,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -3062,7 +3066,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -3523,7 +3531,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -3750,7 +3762,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -4179,7 +4195,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -10044,7 +10064,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -11736,7 +11760,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -13420,7 +13448,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -14302,7 +14334,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); @@ -15636,7 +15672,11 @@ function_name_strval = zend_u_str_case_fold(Z_TYPE_P(function_name), Z_UNIVAL_P(function_name), Z_UNILEN_P(function_name), 1, &function_name_strlen); } - EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + if (ce->get_static_method) { + EX(fbc) = ce->get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } else { + EX(fbc) = zend_std_get_static_method(ce, function_name_strval, function_name_strlen TSRMLS_CC); + } if (!is_const) { efree(function_name_strval.v); http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/call_static.phpt?view=markup&rev=1.1 Index: ZendEngine2/tests/call_static.phpt +++ ZendEngine2/tests/call_static.phpt --TEST-- __callStatic() Magic method --FILE-- <?php class Test { static function __callStatic($fname, $args) { echo $fname, '() called with ', count($args), " arguments\n"; } } call_user_func("Test::Two", 'A', 'B'); call_user_func(array("Test", "Three"), NULL, 0, false); Test::Four(5, 6, 7, 8); --EXPECT-- two() called with 2 arguments three() called with 3 arguments four() called with 4 arguments
« previous php.zend-engine.cvs (#5914) next »