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 */
spl_add_class_name(zval * list,zend_class_entry * pce,int allow,int ce_flags)24 void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
25 {
26 if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
27 zval *tmp;
28
29 if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
30 zval t;
31 ZVAL_STR_COPY(&t, pce->name);
32 zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
33 }
34 }
35 }
36 /* }}} */
37
38 /* {{{ spl_add_interfaces */
spl_add_interfaces(zval * list,zend_class_entry * pce,int allow,int ce_flags)39 void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
40 {
41 if (pce->num_interfaces) {
42 ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
43 for (uint32_t num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
44 spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
45 }
46 }
47 }
48 /* }}} */
49
50 /* {{{ spl_add_traits */
spl_add_traits(zval * list,zend_class_entry * pce,int allow,int ce_flags)51 void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
52 {
53 zend_class_entry *trait;
54
55 for (uint32_t num_traits = 0; num_traits < pce->num_traits; num_traits++) {
56 trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
57 pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
58 ZEND_ASSERT(trait);
59 spl_add_class_name(list, trait, allow, ce_flags);
60 }
61 }
62 /* }}} */
63
64
65 /* {{{ spl_add_classes */
spl_add_classes(zend_class_entry * pce,zval * list,bool sub,int allow,int ce_flags)66 void spl_add_classes(zend_class_entry *pce, zval *list, bool sub, int allow, int ce_flags)
67 {
68 ZEND_ASSERT(pce);
69 spl_add_class_name(list, pce, allow, ce_flags);
70 if (sub) {
71 spl_add_interfaces(list, pce, allow, ce_flags);
72 while (pce->parent) {
73 pce = pce->parent;
74 spl_add_classes(pce, list, sub, allow, ce_flags);
75 }
76 }
77 }
78 /* }}} */
79
spl_set_private_debug_info_property(const zend_class_entry * ce,const char * property,size_t property_len,HashTable * debug_info,zval * value)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 {
88 zend_string *mangled_named = zend_mangle_property_name(
89 ZSTR_VAL(ce->name),
90 ZSTR_LEN(ce->name),
91 property,
92 property_len,
93 /* persistent */ false
94 );
95 zend_hash_update(debug_info, mangled_named, value);
96 zend_string_release_ex(mangled_named, /* persistent */ false);
97 }
98