mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Added missing class_uses(..) function to SPL to mirror class_implements(..).
# Was pointed out as missing in bug #55266.
This commit is contained in:
parent
9a483afa5b
commit
1fc4bc1d56
5 changed files with 54 additions and 0 deletions
4
NEWS
4
NEWS
|
@ -12,6 +12,10 @@
|
|||
. Dropped restriction of not setting the same value multiple times, the last
|
||||
one holds. (giovanni at giacobbi dot net, fat)
|
||||
|
||||
- SPL extension:
|
||||
. Added missing class_uses(..) as pointed out by #55266 (Stefan)
|
||||
|
||||
|
||||
14 Jul 2011, PHP 5.4.0 Alpha 2
|
||||
- General improvements:
|
||||
. Zend Signal Handling. (Lucas Nealan,Arnaud Le Blanc,Brian Shire, Ilia)
|
||||
|
|
|
@ -166,6 +166,35 @@ PHP_FUNCTION(class_implements)
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array class_uses(mixed what [, bool autoload ])
|
||||
Return all traits used by a class. */
|
||||
PHP_FUNCTION(class_uses)
|
||||
{
|
||||
zval *obj;
|
||||
zend_bool autoload = 1;
|
||||
zend_class_entry *ce;
|
||||
|
||||
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (Z_TYPE_P(obj) == IS_STRING) {
|
||||
if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else {
|
||||
ce = Z_OBJCE_P(obj);
|
||||
}
|
||||
|
||||
array_init(return_value);
|
||||
spl_add_traits(return_value, ce, 1, ZEND_ACC_TRAIT TSRMLS_CC);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \
|
||||
spl_add_classes(spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC)
|
||||
|
||||
|
@ -933,6 +962,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_implements, 0, 0, 1)
|
|||
ZEND_ARG_INFO(0, autoload)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_uses, 0, 0, 1)
|
||||
ZEND_ARG_INFO(0, what)
|
||||
ZEND_ARG_INFO(0, autoload)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
|
||||
ZEND_BEGIN_ARG_INFO(arginfo_spl_classes, 0)
|
||||
ZEND_END_ARG_INFO()
|
||||
|
||||
|
@ -977,6 +1012,7 @@ const zend_function_entry spl_functions[] = {
|
|||
PHP_FE(spl_autoload_call, arginfo_spl_autoload_call)
|
||||
PHP_FE(class_parents, arginfo_class_parents)
|
||||
PHP_FE(class_implements, arginfo_class_implements)
|
||||
PHP_FE(class_uses, arginfo_class_uses)
|
||||
PHP_FE(spl_object_hash, arginfo_spl_object_hash)
|
||||
#ifdef SPL_ITERATORS_H
|
||||
PHP_FE(iterator_to_array, arginfo_iterator_to_array)
|
||||
|
|
|
@ -85,6 +85,7 @@ extern zend_spl_globals spl_globals;
|
|||
PHP_FUNCTION(spl_classes);
|
||||
PHP_FUNCTION(class_parents);
|
||||
PHP_FUNCTION(class_implements);
|
||||
PHP_FUNCTION(class_uses);
|
||||
|
||||
PHPAPI void php_spl_object_hash(zval *obj, char* md5str TSRMLS_DC);
|
||||
|
||||
|
|
|
@ -103,6 +103,18 @@ void spl_add_interfaces(zval *list, zend_class_entry * pce, int allow, int ce_fl
|
|||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ spl_add_traits */
|
||||
void spl_add_traits(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC)
|
||||
{
|
||||
zend_uint num_traits;
|
||||
|
||||
for (num_traits = 0; num_traits < pce->num_traits; num_traits++) {
|
||||
spl_add_class_name(list, pce->traits[num_traits], allow, ce_flags TSRMLS_CC);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ spl_add_classes */
|
||||
int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC)
|
||||
{
|
||||
|
|
|
@ -62,6 +62,7 @@ void spl_register_property( zend_class_entry * class_entry, char *prop_name, int
|
|||
*/
|
||||
void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
|
||||
void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
|
||||
void spl_add_traits(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC);
|
||||
int spl_add_classes(zend_class_entry *pce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC);
|
||||
|
||||
/* caller must efree(return) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue