summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2016-01-21 14:31:03 +0800
committerXinchen Hui <laruence@gmail.com>2016-01-21 14:31:03 +0800
commit145555f81cdf7eee69a8fc80f4fefeac93949935 (patch)
tree0bf5427c589e524d995daa5e76a51cf57e8cb74e
parent2ee73ee094ab33b917e350b7171a543bd2b24947 (diff)
downloadphp-git-145555f81cdf7eee69a8fc80f4fefeac93949935.tar.gz
Cover overloaded functions
-rw-r--r--Zend/tests/overloaded_func_001.phpt15
-rw-r--r--Zend/tests/overloaded_func_002.phpt13
-rw-r--r--Zend/zend_builtin_functions.c53
3 files changed, 79 insertions, 2 deletions
diff --git a/Zend/tests/overloaded_func_001.phpt b/Zend/tests/overloaded_func_001.phpt
new file mode 100644
index 0000000000..28df6b6329
--- /dev/null
+++ b/Zend/tests/overloaded_func_001.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Overloaded function 001
+--SKIPF--
+<?php
+if (!PHP_DEBUG) die("skip only run in debug version");
+?>
+--FILE--
+<?php
+var_dump(_ZendTestClass::test());
+?>
+--EXPECTF--
+Fatal error: Uncaught Error: Cannot call overloaded function for non-object in %soverloaded_func_001.php:%d
+Stack trace:
+#0 {main}
+ thrown in %soverloaded_func_001.php on line %d
diff --git a/Zend/tests/overloaded_func_002.phpt b/Zend/tests/overloaded_func_002.phpt
new file mode 100644
index 0000000000..1d7dc47b4d
--- /dev/null
+++ b/Zend/tests/overloaded_func_002.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Overloaded function 002
+--SKIPF--
+<?php
+if (!PHP_DEBUG) die("skip only run in debug version");
+?>
+--FILE--
+<?php
+$a = new _ZendTestClass();
+var_dump($a->{trim(" test")}());
+?>
+--EXPECT--
+NULL
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index eba6ce38d2..07f8ac4738 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -34,6 +34,7 @@
#if ZEND_DEBUG
static zend_class_entry *zend_test_interface;
static zend_class_entry *zend_test_class;
+static zend_object_handlers zend_test_class_handlers;
#endif
static ZEND_FUNCTION(zend_version);
@@ -262,6 +263,50 @@ ZEND_END_ARG_INFO()
/* }}} */
+#if ZEND_DEBUG
+static zend_object *zend_test_class_new(zend_class_entry *class_type) /* {{{ */ {
+ zend_object *obj = zend_objects_new(class_type);
+ obj->handlers = &zend_test_class_handlers;
+ return obj;
+}
+/* }}} */
+
+static zend_function *zend_test_class_method_get(zend_object **object, zend_string *name, const zval *key) /* {{{ */ {
+ zend_internal_function *fptr = emalloc(sizeof(zend_internal_function));
+ fptr->type = ZEND_OVERLOADED_FUNCTION_TEMPORARY;
+ fptr->num_args = 1;
+ fptr->arg_info = NULL;
+ fptr->scope = (*object)->ce;
+ fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
+ fptr->function_name = zend_string_copy(name);
+ fptr->handler = ZEND_FN(zend_test_func);
+ zend_set_function_arg_flags((zend_function*)fptr);
+
+ return (zend_function*)fptr;
+}
+/* }}} */
+
+static zend_function *zend_test_class_static_method_get(zend_class_entry *ce, zend_string *name) /* {{{ */ {
+ zend_internal_function *fptr = emalloc(sizeof(zend_internal_function));
+ fptr->type = ZEND_OVERLOADED_FUNCTION;
+ fptr->num_args = 1;
+ fptr->arg_info = NULL;
+ fptr->scope = ce;
+ fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER|ZEND_ACC_STATIC;
+ fptr->function_name = name;
+ fptr->handler = ZEND_FN(zend_test_func);
+ zend_set_function_arg_flags((zend_function*)fptr);
+
+ return (zend_function*)fptr;
+}
+/* }}} */
+
+static int zend_test_class_call_method(zend_string *method, zend_object *object, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ {
+ return 0;
+}
+/* }}} */
+#endif
+
static const zend_function_entry builtin_functions[] = { /* {{{ */
ZEND_FE(zend_version, arginfo_zend__void)
ZEND_FE(func_num_args, arginfo_zend__void)
@@ -351,6 +396,12 @@ ZEND_MINIT_FUNCTION(core) { /* {{{ */
INIT_CLASS_ENTRY(class_entry, "_ZendTestClass", NULL);
zend_test_class = zend_register_internal_class_ex(&class_entry, NULL);
zend_class_implements(zend_test_class, 1, zend_test_interface);
+ zend_test_class->create_object = zend_test_class_new;
+ zend_test_class->get_static_method = zend_test_class_static_method_get;
+
+ memcpy(&zend_test_class_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
+ zend_test_class_handlers.get_method = zend_test_class_method_get;
+ zend_test_class_handlers.call_method = zend_test_class_call_method;
#endif
return SUCCESS;
@@ -2059,8 +2110,6 @@ ZEND_FUNCTION(zend_test_func2)
zend_parse_parameters(ZEND_NUM_ARGS(), "|zz", &arg1, &arg2);
}
-
-
#ifdef ZTS
ZEND_FUNCTION(zend_thread_id)
{