Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9554 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59362 invoked by uid 1010); 25 Apr 2004 16:49:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 59337 invoked from network); 25 Apr 2004 16:49:07 -0000 Received: from unknown (HELO smtprelay02.ispgateway.de) (62.67.200.157) by pb1.pair.com with SMTP; 25 Apr 2004 16:49:07 -0000 Received: (qmail 7942 invoked from network); 25 Apr 2004 16:49:06 -0000 Received: from unknown (HELO eenterphace.org) (494173@[80.138.135.207]) (envelope-sender ) by smtprelay02.ispgateway.de (qmail-ldap-1.03) with SMTP for ; 25 Apr 2004 16:49:06 -0000 Message-ID: <408BEF30.60003@eenterphace.org> Date: Sun, 25 Apr 2004 19:02:40 +0200 User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: de-de, de-at, de, en-us, en MIME-Version: 1.0 To: internals@lists.php.net Content-Type: multipart/mixed; boundary="------------040801030905040906010702" Subject: new_object_array() From: jr@eenterphace.org (Julian Reich) --------------040801030905040906010702 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi all, Referring to call_user_func_array() I would like to suggest a new function: new_object_array(). I'm working on a php5 application framework and I would like to implement something I call an unified factory. The problem is that I don't know how many parameters to expect. Here's an example how it's meant to work: getDbManager('param1', 'param2'); // 1st possibility to get new object $XmlParser = $Kernel->newObject('XmlParser', 'param1', 'param2'); // 2nd possibility to get new object ?> I have written an implementation of new_object_array(); <-- see attachment Perhaps some things need to be rewritten ;) I would be happy if you would consider to include this function in the standard distribution of php. Yours sincerly, Julian Reich --------------040801030905040906010702 Content-Type: text/plain; name="new_object_array.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="new_object_array.c" #include "php.h" ZEND_FUNCTION(new_object_array); zend_function_entry new_object_array_functions[] = { ZEND_FE(new_object_array, NULL) {NULL, NULL, NULL} }; zend_module_entry new_object_array_module_entry = { STANDARD_MODULE_HEADER, "new_object_array()", new_object_array_functions, NULL, NULL, NULL, NULL, NULL, NO_VERSION_YET, STANDARD_MODULE_PROPERTIES }; #if COMPILE_DL_NEW_OBJECT_ARRAY ZEND_GET_MODULE(new_object_array) #endif ZEND_FUNCTION(new_object_array) { zval *object, *constructor_name, *constructor_return_value; zval **class_name, **constructor_parameters; zval ***constructor_real_parameters; zend_class_entry *ce; zend_class_entry **pce; HashTable *constructor_parameters_ht; int count, current = 0; if ((ZEND_NUM_ARGS() != 2) || (zend_get_parameters_ex(2, &class_name, &constructor_parameters) == FAILURE)) { ZEND_WRONG_PARAM_COUNT(); } convert_to_string_ex(class_name); if (zend_lookup_class(Z_STRVAL_PP(class_name), Z_STRLEN_PP(class_name), &pce TSRMLS_CC) == FAILURE) { RETURN_FALSE; } else { ce = *pce; MAKE_STD_ZVAL(object); object_init_ex(object, ce); MAKE_STD_ZVAL(constructor_name); ZVAL_STRING(constructor_name, "__construct", 1); SEPARATE_ZVAL(constructor_parameters); convert_to_array_ex(constructor_parameters); constructor_parameters_ht = Z_ARRVAL_PP(constructor_parameters); count = zend_hash_num_elements(constructor_parameters_ht); constructor_real_parameters = safe_emalloc(sizeof(zval **), count, 0); for (zend_hash_internal_pointer_reset(constructor_parameters_ht); zend_hash_get_current_data(constructor_parameters_ht, (void **) &constructor_real_parameters[current]) == SUCCESS; zend_hash_move_forward(constructor_parameters_ht) ) { current++; } call_user_function_ex(NULL, &object, constructor_name, &constructor_return_value, count, constructor_real_parameters, 0, NULL TSRMLS_CC); *return_value = *object; zval_copy_ctor(return_value); } } --------------040801030905040906010702--