Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:19811 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4006 invoked by uid 1010); 29 Oct 2005 07:18:39 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 3990 invoked from network); 29 Oct 2005 07:18:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Oct 2005 07:18:39 -0000 X-Host-Fingerprint: 198.237.84.92 unknown Linux 2.4/2.6 Received: from ([198.237.84.92:1332] helo=bobsilva.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 87/00-02082-E4223634 for ; Sat, 29 Oct 2005 03:18:38 -0400 Received: from [198.237.84.93] (HELO jake) by bobsilva.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 675556 for internals@lists.php.net; Fri, 28 Oct 2005 20:59:18 -0700 To: Date: Sat, 29 Oct 2005 00:18:24 -0700 Message-ID: <001d01c5dc58$f3676700$5d54edc6@jake> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcXcMVzorR+m3XMbTfeT/DHC/VTuQgAIpNmg X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 In-Reply-To: <001501c5dc31$5cf9a520$5d54edc6@jake> Subject: RE: [PHP-DEV] Follow the object constructor chain ... options From: me@bobsilva.com ("Bob Silva") References: <001501c5dc31$5cf9a520$5d54edc6@jake> I believe I have it working. Anyone see any blatant problems with this? Also, would it make sense to have this functionality in the engine itself? Seeing as that internal classes have inheritance capabilities, it seems logical to have the functionality to call a parent constructor within the engine itself. I could definitely see this being useful within the SPL as its class library continues to grow as well. void pow_call_parent_constructor(zval *object TSRMLS_DC) { zend_class_entry *ce = EG(function_state_ptr)->function->common.scope; if (ce->parent && ce->parent->constructor) { zval *retval_ptr; zend_fcall_info fci; zend_fcall_info_cache fcc; if (!(ce->parent->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { return; } fci.size = sizeof(fci); fci.function_table = NULL; fci.function_name = NULL; fci.symbol_table = NULL; fci.object_pp = &object; fci.retval_ptr_ptr = &retval_ptr; fci.param_count = 0; fci.params = NULL; fci.no_separation = 1; fcc.initialized = 1; fcc.function_handler = ce->parent->constructor; fcc.calling_scope = ce; fcc.object_pp = &object; if (zend_call_function(&fci, &fcc TSRMLS_CC) == FAILURE) { return; } if (retval_ptr) { zval_ptr_dtor(&retval_ptr); } } } Forgive me if its crude, but it appears to work. Bob -----Original Message----- From: Bob Silva [mailto:me@bobsilva.com] Sent: Friday, October 28, 2005 7:35 PM To: internals@lists.php.net Subject: [PHP-DEV] Follow the object constructor chain ... options What would be the suggested method of simulating parent::__construct in C-level objects? I looked through the source and could find no examples to draw from. Since my base object is the foundation of my extension, its constructor has to be called on each derived object creation. I have a few ideas that have to do with looping through ce->parent and zend_call_function. Was wondering if you guys can offer some of your experience on how you would approach this problem. Bob Silva