This repository was archived by the owner on Jun 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallee.c
More file actions
114 lines (99 loc) · 2.7 KB
/
Copy pathcallee.c
File metadata and controls
114 lines (99 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "zend_closures.h"
#include "ext/standard/info.h"
#include "Zend/zend_generators.h"
#include "ext/standard/php_rand.h"
#include "php_callee.h"
PHP_FUNCTION(callee)
{
zend_execute_data *ptr, *skip, *call = NULL;
zend_object *object;
zend_function *func;
zend_string *function_name;
if (zend_parse_parameters_none() == FAILURE) {
return;
}
if (!(ptr = EG(current_execute_data))) {
return;
}
if (!ptr->func || !ZEND_USER_CODE(ptr->func->common.type)) {
call = ptr;
ptr = ptr->prev_execute_data;
}
if (ptr) {
/* skip debug_backtrace() */
call = ptr;
ptr = ptr->prev_execute_data;
if (!call) {
call = ptr;
ptr = ptr->prev_execute_data;
}
}
if (!ptr) {
return;
}
/* $this may be passed into regular internal functions */
object = call ? Z_OBJ(call->This) : NULL;
if (call && call->func) {
func = call->func;
function_name = (func->common.scope &&
func->common.scope->trait_aliases) ?
zend_resolve_method_name(
(object ? object->ce : func->common.scope), func) :
func->common.function_name;
} else {
func = NULL;
function_name = NULL;
}
if (!function_name) {
return;
}
if (object) {
zval zv;
Z_ADDREF(call->This);
ZVAL_COPY_VALUE(&zv, &call->This);
array_init(return_value);
add_next_index_zval(return_value, &zv);
add_next_index_str(return_value, zend_string_copy(function_name));
} else if (func->common.scope) {
array_init(return_value);
add_next_index_str(return_value, zend_string_copy(func->common.scope->name));
add_next_index_str(return_value, zend_string_copy(function_name));
} else if (func->op_array.fn_flags & ZEND_ACC_CLOSURE) {
zend_create_fake_closure(return_value, func, func->common.scope, func->common.scope, NULL);
} else {
RETURN_NEW_STR(function_name);
}
}
PHP_MINFO_FUNCTION(callee)
{
php_info_print_table_start();
php_info_print_table_header(2, "callee support", "enabled");
php_info_print_table_end();
}
const zend_function_entry callee_functions[] = {
PHP_FE(callee, NULL)
PHP_FE_END
};
zend_module_entry callee_module_entry = {
STANDARD_MODULE_HEADER,
"callee",
callee_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(callee),
PHP_CALLEE_VERSION,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_CALLEE
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE()
#endif
ZEND_GET_MODULE(callee)
#endif