xref: /PHP-8.1/ext/spl/spl_functions.c (revision 01b3fc03)
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 #include "php_ini.h"
23 #include "ext/standard/info.h"
24 #include "php_spl.h"
25 
26 /* {{{ spl_add_class_name */
spl_add_class_name(zval * list,zend_class_entry * pce,int allow,int ce_flags)27 void spl_add_class_name(zval *list, zend_class_entry *pce, int allow, int ce_flags)
28 {
29 	if (!allow || (allow > 0 && (pce->ce_flags & ce_flags)) || (allow < 0 && !(pce->ce_flags & ce_flags))) {
30 		zval *tmp;
31 
32 		if ((tmp = zend_hash_find(Z_ARRVAL_P(list), pce->name)) == NULL) {
33 			zval t;
34 			ZVAL_STR_COPY(&t, pce->name);
35 			zend_hash_add(Z_ARRVAL_P(list), pce->name, &t);
36 		}
37 	}
38 }
39 /* }}} */
40 
41 /* {{{ spl_add_interfaces */
spl_add_interfaces(zval * list,zend_class_entry * pce,int allow,int ce_flags)42 void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_flags)
43 {
44 	uint32_t num_interfaces;
45 
46 	if (pce->num_interfaces) {
47 		ZEND_ASSERT(pce->ce_flags & ZEND_ACC_LINKED);
48 		for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) {
49 			spl_add_class_name(list, pce->interfaces[num_interfaces], allow, ce_flags);
50 		}
51 	}
52 }
53 /* }}} */
54 
55 /* {{{ spl_add_traits */
spl_add_traits(zval * list,zend_class_entry * pce,int allow,int ce_flags)56 void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags)
57 {
58 	uint32_t num_traits;
59 	zend_class_entry *trait;
60 
61 	for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
62 		trait = zend_fetch_class_by_name(pce->trait_names[num_traits].name,
63 			pce->trait_names[num_traits].lc_name, ZEND_FETCH_CLASS_TRAIT);
64 		ZEND_ASSERT(trait);
65 		spl_add_class_name(list, trait, allow, ce_flags);
66 	}
67 }
68 /* }}} */
69 
70 
71 /* {{{ spl_add_classes */
spl_add_classes(zend_class_entry * pce,zval * list,int sub,int allow,int ce_flags)72 int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags)
73 {
74 	if (!pce) {
75 		return 0;
76 	}
77 	spl_add_class_name(list, pce, allow, ce_flags);
78 	if (sub) {
79 		spl_add_interfaces(list, pce, allow, ce_flags);
80 		while (pce->parent) {
81 			pce = pce->parent;
82 			spl_add_classes(pce, list, sub, allow, ce_flags);
83 		}
84 	}
85 	return 0;
86 }
87 /* }}} */
88 
spl_gen_private_prop_name(zend_class_entry * ce,char * prop_name,int prop_len)89 zend_string * spl_gen_private_prop_name(zend_class_entry *ce, char *prop_name, int prop_len) /* {{{ */
90 {
91 	return zend_mangle_property_name(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), prop_name, prop_len, 0);
92 }
93 /* }}} */
94