summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rwxr-xr-xext/spl/php_spl.c36
-rwxr-xr-xext/spl/php_spl.h1
-rwxr-xr-xext/spl/spl_functions.c12
-rwxr-xr-xext/spl/spl_functions.h1
5 files changed, 54 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index df2fa523a0..931cd67aec 100644
--- a/NEWS
+++ b/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)
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index de59a02c93..8b49b6c5e1 100755
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -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)
diff --git a/ext/spl/php_spl.h b/ext/spl/php_spl.h
index ee6482548a..7c6e174e97 100755
--- a/ext/spl/php_spl.h
+++ b/ext/spl/php_spl.h
@@ -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);
diff --git a/ext/spl/spl_functions.c b/ext/spl/spl_functions.c
index 1d20b6a7f2..84976bd0ad 100755
--- a/ext/spl/spl_functions.c
+++ b/ext/spl/spl_functions.c
@@ -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)
{
diff --git a/ext/spl/spl_functions.h b/ext/spl/spl_functions.h
index d5e3e72670..69feb3834f 100755
--- a/ext/spl/spl_functions.h
+++ b/ext/spl/spl_functions.h
@@ -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) */