/src/php-src/ext/spl/spl_functions.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Copyright (c) The PHP Group | |
4 | | +----------------------------------------------------------------------+ |
5 | | | This source file is subject to version 3.01 of the PHP license, | |
6 | | | that is bundled with this package in the file LICENSE, and is | |
7 | | | available through the world-wide-web at the following url: | |
8 | | | https://www.php.net/license/3_01.txt | |
9 | | | If you did not receive a copy of the PHP license and are unable to | |
10 | | | obtain it through the world-wide-web, please send a note to | |
11 | | | license@php.net so we can mail you a copy immediately. | |
12 | | +----------------------------------------------------------------------+ |
13 | | | Authors: Marcus Boerger <helly@php.net> | |
14 | | +----------------------------------------------------------------------+ |
15 | | */ |
16 | | |
17 | | #ifdef HAVE_CONFIG_H |
18 | | #include <config.h> |
19 | | #endif |
20 | | |
21 | | #include "php.h" |
22 | | |
23 | | /* {{{ spl_add_class_name */ |
24 | | void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags) |
25 | 550 | { |
26 | 550 | if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) { |
27 | 275 | zval *tmp; |
28 | | |
29 | 275 | if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) { |
30 | 275 | zval t; |
31 | 275 | ZVAL_STR_COPY(&t, pce->name); |
32 | 275 | zend_hash_add(Z_ARRVAL_P(list), pce->name, &t); |
33 | 275 | } |
34 | 275 | } |
35 | 550 | } |
36 | | /* }}} */ |
37 | | |
38 | | /* {{{ spl_add_interfaces */ |
39 | | void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags) |
40 | 0 | { |
41 | 0 | if (pce->num_interfaces) { |
42 | 0 | ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED); |
43 | 0 | for (uint32_t num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) { |
44 | 0 | spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags); |
45 | 0 | } |
46 | 0 | } |
47 | 0 | } |
48 | | /* }}} */ |
49 | | |
50 | | /* {{{ spl_add_traits */ |
51 | | void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags) |
52 | 0 | { |
53 | 0 | zend_class_entry *trait; |
54 | |
|
55 | 0 | for (uint32_t num_traits = 0; num_traits < pce->num_traits; num_traits++) { |
56 | 0 | trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name, |
57 | 0 | pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT); |
58 | 0 | ZEND_ASSERT(trait); |
59 | 0 | spl_add_class_name(list, trait, allow, ce_flags); |
60 | 0 | } |
61 | 0 | } |
62 | | /* }}} */ |
63 | | |
64 | | |
65 | | /* {{{ spl_add_classes */ |
66 | | void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags) |
67 | 550 | { |
68 | 550 | ZEND_ASSERT(pce); |
69 | 550 | spl_add_class_name(list, pce, allow, ce_flags); |
70 | 550 | if (sub) { |
71 | 0 | spl_add_interfaces(list, pce, allow, ce_flags); |
72 | 0 | while (pce->parent) { |
73 | 0 | pce = pce->parent; |
74 | 0 | spl_add_classes(pce, list, sub, allow, ce_flags); |
75 | 0 | } |
76 | 0 | } |
77 | 550 | } |
78 | | /* }}} */ |
79 | | |
80 | | void spl_set_private_debug_info_property( |
81 | | const zend_class_entry *ce, |
82 | | const char *property, |
83 | | size_t property_len, |
84 | | HashTable *debug_info, |
85 | | zval *value |
86 | | ) |
87 | 68 | { |
88 | 68 | zend_string *mangled_named = zend_mangle_property_name( |
89 | 68 | ZSTR_VAL(ce->name), |
90 | 68 | ZSTR_LEN(ce->name), |
91 | 68 | property, |
92 | 68 | property_len, |
93 | | /* persistent */ false |
94 | 68 | ); |
95 | 68 | zend_hash_update(debug_info, mangled_named, value); |
96 | 68 | zend_string_release_ex(mangled_named, /* persistent */ false); |
97 | 68 | } |