]> granicus.if.org Git - php/commitdiff
Cover overloaded functions
authorXinchen Hui <laruence@gmail.com>
Thu, 21 Jan 2016 06:31:03 +0000 (14:31 +0800)
committerXinchen Hui <laruence@gmail.com>
Thu, 21 Jan 2016 06:31:03 +0000 (14:31 +0800)
Zend/tests/overloaded_func_001.phpt [new file with mode: 0644]
Zend/tests/overloaded_func_002.phpt [new file with mode: 0644]
Zend/zend_builtin_functions.c

diff --git a/Zend/tests/overloaded_func_001.phpt b/Zend/tests/overloaded_func_001.phpt
new file mode 100644 (file)
index 0000000..28df6b6
--- /dev/null
@@ -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 (file)
index 0000000..1d7dc47
--- /dev/null
@@ -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
index eba6ce38d2bc92035b0e997b1c987dbbbe06b95a..07f8ac4738063353a473f587b7df29663266f02b 100644 (file)
@@ -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)
 {