Skip to content

Commit 145555f

Browse files
committed
Cover overloaded functions
1 parent 2ee73ee commit 145555f

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

Zend/tests/overloaded_func_001.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Overloaded function 001
3+
--SKIPF--
4+
<?php
5+
if (!PHP_DEBUG) die("skip only run in debug version");
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(_ZendTestClass::test());
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught Error: Cannot call overloaded function for non-object in %soverloaded_func_001.php:%d
13+
Stack trace:
14+
#0 {main}
15+
thrown in %soverloaded_func_001.php on line %d

Zend/tests/overloaded_func_002.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Overloaded function 002
3+
--SKIPF--
4+
<?php
5+
if (!PHP_DEBUG) die("skip only run in debug version");
6+
?>
7+
--FILE--
8+
<?php
9+
$a = new _ZendTestClass();
10+
var_dump($a->{trim(" test")}());
11+
?>
12+
--EXPECT--
13+
NULL

Zend/zend_builtin_functions.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#if ZEND_DEBUG
3535
static zend_class_entry *zend_test_interface;
3636
static zend_class_entry *zend_test_class;
37+
static zend_object_handlers zend_test_class_handlers;
3738
#endif
3839

3940
static ZEND_FUNCTION(zend_version);
@@ -262,6 +263,50 @@ ZEND_END_ARG_INFO()
262263

263264
/* }}} */
264265

266+
#if ZEND_DEBUG
267+
static zend_object *zend_test_class_new(zend_class_entry *class_type) /* {{{ */ {
268+
zend_object *obj = zend_objects_new(class_type);
269+
obj->handlers = &zend_test_class_handlers;
270+
return obj;
271+
}
272+
/* }}} */
273+
274+
static zend_function *zend_test_class_method_get(zend_object **object, zend_string *name, const zval *key) /* {{{ */ {
275+
zend_internal_function *fptr = emalloc(sizeof(zend_internal_function));
276+
fptr->type = ZEND_OVERLOADED_FUNCTION_TEMPORARY;
277+
fptr->num_args = 1;
278+
fptr->arg_info = NULL;
279+
fptr->scope = (*object)->ce;
280+
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
281+
fptr->function_name = zend_string_copy(name);
282+
fptr->handler = ZEND_FN(zend_test_func);
283+
zend_set_function_arg_flags((zend_function*)fptr);
284+
285+
return (zend_function*)fptr;
286+
}
287+
/* }}} */
288+
289+
static zend_function *zend_test_class_static_method_get(zend_class_entry *ce, zend_string *name) /* {{{ */ {
290+
zend_internal_function *fptr = emalloc(sizeof(zend_internal_function));
291+
fptr->type = ZEND_OVERLOADED_FUNCTION;
292+
fptr->num_args = 1;
293+
fptr->arg_info = NULL;
294+
fptr->scope = ce;
295+
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER|ZEND_ACC_STATIC;
296+
fptr->function_name = name;
297+
fptr->handler = ZEND_FN(zend_test_func);
298+
zend_set_function_arg_flags((zend_function*)fptr);
299+
300+
return (zend_function*)fptr;
301+
}
302+
/* }}} */
303+
304+
static int zend_test_class_call_method(zend_string *method, zend_object *object, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ {
305+
return 0;
306+
}
307+
/* }}} */
308+
#endif
309+
265310
static const zend_function_entry builtin_functions[] = { /* {{{ */
266311
ZEND_FE(zend_version, arginfo_zend__void)
267312
ZEND_FE(func_num_args, arginfo_zend__void)
@@ -351,6 +396,12 @@ ZEND_MINIT_FUNCTION(core) { /* {{{ */
351396
INIT_CLASS_ENTRY(class_entry, "_ZendTestClass", NULL);
352397
zend_test_class = zend_register_internal_class_ex(&class_entry, NULL);
353398
zend_class_implements(zend_test_class, 1, zend_test_interface);
399+
zend_test_class->create_object = zend_test_class_new;
400+
zend_test_class->get_static_method = zend_test_class_static_method_get;
401+
402+
memcpy(&zend_test_class_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
403+
zend_test_class_handlers.get_method = zend_test_class_method_get;
404+
zend_test_class_handlers.call_method = zend_test_class_call_method;
354405
#endif
355406

356407
return SUCCESS;
@@ -2059,8 +2110,6 @@ ZEND_FUNCTION(zend_test_func2)
20592110

20602111
zend_parse_parameters(ZEND_NUM_ARGS(), "|zz", &arg1, &arg2);
20612112
}
2062-
2063-
20642113
#ifdef ZTS
20652114
ZEND_FUNCTION(zend_thread_id)
20662115
{

0 commit comments

Comments
 (0)