gron Sat, 23 Jul 2011 19:08:43 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313640
Log:
Added missing class_uses(..) function to SPL to mirror class_implements(..).
# Was pointed out as missing in bug #55266.
Bug: https://bugs.php.net/55266 (Assigned) Traits vs Type hints
Changed paths:
U php/php-src/branches/PHP_5_4/NEWS
U php/php-src/branches/PHP_5_4/ext/spl/php_spl.c
U php/php-src/branches/PHP_5_4/ext/spl/php_spl.h
U php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c
U php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h
U php/php-src/trunk/NEWS
U php/php-src/trunk/ext/spl/php_spl.c
U php/php-src/trunk/ext/spl/php_spl.h
U php/php-src/trunk/ext/spl/spl_functions.c
U php/php-src/trunk/ext/spl/spl_functions.h
Modified: php/php-src/branches/PHP_5_4/NEWS
===================================================================
--- php/php-src/branches/PHP_5_4/NEWS 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/branches/PHP_5_4/NEWS 2011-07-23 19:08:43 UTC (rev 313640)
@@ -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)
Modified: php/php-src/branches/PHP_5_4/ext/spl/php_spl.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/php_spl.c 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/branches/PHP_5_4/ext/spl/php_spl.c 2011-07-23 19:08:43 UTC (rev 313640)
@@ -166,6 +166,35 @@
}
/* }}} */
+/* {{{ 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_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 @@
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)
Modified: php/php-src/branches/PHP_5_4/ext/spl/php_spl.h
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/php_spl.h 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/branches/PHP_5_4/ext/spl/php_spl.h 2011-07-23 19:08:43 UTC (rev 313640)
@@ -85,6 +85,7 @@
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);
Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/branches/PHP_5_4/ext/spl/spl_functions.c 2011-07-23 19:08:43 UTC (rev 313640)
@@ -103,6 +103,18 @@
}
/* }}} */
+/* {{{ 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)
{
Modified: php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h
===================================================================
--- php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/branches/PHP_5_4/ext/spl/spl_functions.h 2011-07-23 19:08:43 UTC (rev 313640)
@@ -62,6 +62,7 @@
*/
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) */
Modified: php/php-src/trunk/NEWS
===================================================================
--- php/php-src/trunk/NEWS 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/trunk/NEWS 2011-07-23 19:08:43 UTC (rev 313640)
@@ -205,6 +205,7 @@
. Added RegexIterator::getRegex() method. (Joshua Thijssen)
. Added SplObjectStorage::getHash() hook. (Etienne)
. Added CallbackFilterIterator and RecursiveCallbackFilterIterator (Arnaud)
+ . Added missing class_uses(..) as pointed out by #55266 (Stefan)
- Improved XSL extension:
. Added XsltProcessor::setSecurityPrefs($options) and getSecurityPrefs() to
Modified: php/php-src/trunk/ext/spl/php_spl.c
===================================================================
--- php/php-src/trunk/ext/spl/php_spl.c 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/trunk/ext/spl/php_spl.c 2011-07-23 19:08:43 UTC (rev 313640)
@@ -166,6 +166,35 @@
}
/* }}} */
+/* {{{ 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_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 @@
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)
Modified: php/php-src/trunk/ext/spl/php_spl.h
===================================================================
--- php/php-src/trunk/ext/spl/php_spl.h 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/trunk/ext/spl/php_spl.h 2011-07-23 19:08:43 UTC (rev 313640)
@@ -85,6 +85,7 @@
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);
Modified: php/php-src/trunk/ext/spl/spl_functions.c
===================================================================
--- php/php-src/trunk/ext/spl/spl_functions.c 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/trunk/ext/spl/spl_functions.c 2011-07-23 19:08:43 UTC (rev 313640)
@@ -103,6 +103,18 @@
}
/* }}} */
+/* {{{ 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)
{
Modified: php/php-src/trunk/ext/spl/spl_functions.h
===================================================================
--- php/php-src/trunk/ext/spl/spl_functions.h 2011-07-23 18:19:12 UTC (rev 313639)
+++ php/php-src/trunk/ext/spl/spl_functions.h 2011-07-23 19:08:43 UTC (rev 313640)
@@ -62,6 +62,7 @@
*/
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) */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php