Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28635 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57316 invoked by uid 1010); 30 Mar 2007 21:15:25 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 57300 invoked from network); 30 Mar 2007 21:15:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2007 21:15:25 -0000 Received: from [127.0.0.1] ([127.0.0.1:6201]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 54/FA-01435-DED7D064 for ; Fri, 30 Mar 2007 16:15:25 -0500 Authentication-Results: pb1.pair.com header.from=jani.taskinen@sci.fi; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jani.taskinen@sci.fi; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sci.fi from 63.208.196.171 cause and error) X-PHP-List-Original-Sender: jani.taskinen@sci.fi X-Host-Fingerprint: 63.208.196.171 outbound.mailhop.org FreeBSD 4.6-4.9 Received: from [63.208.196.171] ([63.208.196.171:3231] helo=outbound.mailhop.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/10-18696-FCFEA064 for ; Wed, 28 Mar 2007 17:44:32 -0500 Received: from cs136054.pp.htv.fi ([213.243.136.54] helo=[192.168.1.100]) by outbound.mailhop.org with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1HWgsX-000G44-Cq; Wed, 28 Mar 2007 18:44:29 -0400 X-Mail-Handler: MailHop Outbound by DynDNS X-Originating-IP: 213.243.136.54 X-Report-Abuse-To: abuse@dyndns.com (see http://www.mailhop.org/outbound/abuse.html for abuse reporting information) X-MHO-User: jtaskine Message-ID: <460AEFCF.9020005@sci.fi> Date: Thu, 29 Mar 2007 01:44:31 +0300 Reply-To: sniper@iki.fi User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: internals@lists.php.net CC: iliaa@php.net Content-Type: multipart/mixed; boundary="------------060105080400070809010209" Subject: [PATCH] Allow get_declared_classes() and get_declared_interfaces() return user/internal class/interface separately From: jani.taskinen@sci.fi (Jani Taskinen) --------------060105080400070809010209 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch allows get_declared_classes and get_declared_interfaces() functions to return the information in associative array with "internal" and "user" keys when passed the optional parameter. And makes them a bit more consistent with similar functions like get_defined_functions().. Example: [jani@localhost php_5_2tst]$ sapi/cli/php -r 'class foobar {} print_r(get_declared_classes(true));'|less Array ( [internal] => Array ( [0] => stdClass [1] => Exception [2] => ErrorException [3] => __PHP_Incomplete_Class [4] => php_user_filter [5] => Directory [6] => DateTime [7] => DateTimeZone ) [user] => Array ( [0] => foobar ) ) --Jani --------------060105080400070809010209 Content-Type: text/plain; name="zend_builtin_functions.c.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="zend_builtin_functions.c.patch" Index: zend_builtin_functions.c =================================================================== RCS file: /repository/ZendEngine2/zend_builtin_functions.c,v retrieving revision 1.277.2.12.2.16 diff -u -r1.277.2.12.2.16 zend_builtin_functions.c --- zend_builtin_functions.c 24 Feb 2007 02:17:23 -0000 1.277.2.12.2.16 +++ zend_builtin_functions.c 28 Mar 2007 12:19:54 -0000 @@ -1333,46 +1333,76 @@ zval *array = va_arg(args, zval *); zend_uint mask = va_arg(args, zend_uint); zend_uint comply = va_arg(args, zend_uint); - zend_uint comply_mask = (comply)? mask:0; + zend_uint comply_mask = (comply) ? mask : 0; zend_class_entry *ce = *pce; - if ((hash_key->nKeyLength==0 || hash_key->arKey[0]!=0) + if ((hash_key->nKeyLength == 0 || hash_key->arKey[0] != 0) && (comply_mask == (ce->ce_flags & mask))) { - add_next_index_stringl(array, ce->name, ce->name_length, 1); + + if (num_args == 3) { + add_next_index_stringl(array, ce->name, ce->name_length, 1); + } else if (num_args == 5) { + zval *internal_ar = va_arg(args, zval *), + *user_ar = va_arg(args, zval *); + + if (ce->type == ZEND_INTERNAL_CLASS) { + add_next_index_stringl(internal_ar, ce->name, ce->name_length, 1); + } else if (ce->type == ZEND_USER_CLASS) { + add_next_index_stringl(user_ar, ce->name, ce->name_length, 1); + } + } } return ZEND_HASH_APPLY_KEEP; } - -/* {{{ proto array get_declared_classes() - Returns an array of all declared classes. */ -ZEND_FUNCTION(get_declared_classes) +static void do_get_declared_classes_or_interfaces(INTERNAL_FUNCTION_PARAMETERS, zend_uint mask, zend_uint comply) { - zend_uint mask = ZEND_ACC_INTERFACE; - zend_uint comply = 0; + zend_bool return_assoc = 0; - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &return_assoc) == FAILURE) { + return; } - + array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) copy_class_or_interface_name, 3, return_value, mask, comply); + + if (return_assoc) + { + zval *internal; + zval *user; + + MAKE_STD_ZVAL(internal); + MAKE_STD_ZVAL(user); + + array_init(internal); + array_init(user); + + zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) copy_class_or_interface_name, 5, return_value, mask, comply, internal, user); + zend_hash_add(Z_ARRVAL_P(return_value), "internal", sizeof("internal"), (void **) &internal, sizeof(zval *), NULL); + zend_hash_add(Z_ARRVAL_P(return_value), "user", sizeof("user"), (void **) &user, sizeof(zval *), NULL); + } else { + zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) copy_class_or_interface_name, 3, return_value, mask, comply); + } } /* }}} */ -/* {{{ proto array get_declared_interfaces() - Returns an array of all declared interfaces. */ +/* {{{ proto array get_declared_classes([bool return_assoc]) + Returns an array of declared classes. */ +ZEND_FUNCTION(get_declared_classes) +{ + zend_uint mask = ZEND_ACC_INTERFACE; + zend_uint comply = 0; + + do_get_declared_classes_or_interfaces(INTERNAL_FUNCTION_PARAM_PASSTHRU, mask, comply); +} + +/* {{{ proto array get_declared_interfaces([bool assoc]) + Returns an array of declared interfaces. */ ZEND_FUNCTION(get_declared_interfaces) { zend_uint mask = ZEND_ACC_INTERFACE; zend_uint comply = 1; - if (ZEND_NUM_ARGS() != 0) { - ZEND_WRONG_PARAM_COUNT(); - } - - array_init(return_value); - zend_hash_apply_with_arguments(EG(class_table), (apply_func_args_t) copy_class_or_interface_name, 3, return_value, mask, comply); + do_get_declared_classes_or_interfaces(INTERNAL_FUNCTION_PARAM_PASSTHRU, mask, comply); } /* }}} */ Index: tests/017.phpt =================================================================== RCS file: /repository/ZendEngine2/tests/017.phpt,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 017.phpt --- tests/017.phpt 21 Nov 2006 11:11:39 -0000 1.1.2.2 +++ tests/017.phpt 28 Mar 2007 12:19:54 -0000 @@ -28,7 +28,11 @@ var_dump(gettype(get_defined_functions())); var_dump(count(get_defined_functions())); -var_dump(get_declared_interfaces(true)); +var_dump(get_declared_classes(true,true)); +var_dump(gettype(get_declared_classes())); +var_dump(count(get_declared_classes())); + +var_dump(get_declared_interfaces(true,true)); var_dump(gettype(get_declared_interfaces())); var_dump(count(get_declared_interfaces())); @@ -67,7 +71,12 @@ string(5) "array" int(%d) -Warning: Wrong parameter count for get_declared_interfaces() in %s on line %d +Warning: get_declared_classes() expects at most 1 parameter, 2 given in %s on line %d +NULL +string(5) "array" +int(%d) + +Warning: get_declared_interfaces() expects at most 1 parameter, 2 given in %s on line %d NULL string(5) "array" int(%d) @@ -80,3 +89,4 @@ string(5) "array" int(%d) Done + --------------060105080400070809010209--