Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:6763 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61556 invoked by uid 1010); 3 Jan 2004 09:16:56 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 61532 invoked from network); 3 Jan 2004 09:16:56 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 3 Jan 2004 09:16:56 -0000 Received: from [192.168.1.100] (p508EA28C.dip.t-dialin.net [80.142.162.140]) by shiva.mind.de (Postfix) with ESMTP id 75D7997B66; Sat, 3 Jan 2004 10:16:46 +0100 (CET) Date: Sat, 3 Jan 2004 10:14:55 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <931034707078.20040103101455@marcus-boerger.de> To: Jon Parise Cc: internals@lists.php.net In-Reply-To: <20040103012111.GC23760@csh.rit.edu> References: <20040103000120.GA23760@csh.rit.edu> <20040103000921.GA3712@gravitonic.com> <20040103002841.GB23760@csh.rit.edu> <20040103010033.GA4245@gravitonic.com> <20040103012111.GC23760@csh.rit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Custom object creation and reference counts From: helly@php.net (Marcus Boerger) Hello Jon, Saturday, January 3, 2004, 2:21:12 AM, you wrote: > On Fri, Jan 02, 2004 at 05:00:33PM -0800, Andrei Zmievski wrote: >> > It appears to be a side-effect of not defining the 'scope' field in >> > the zend_internal_function call that is invokved from my custom >> > 'constructor_get' handler. If the 'scope' field is NULL, my object >> > is treated as a reference. If I assign my class entry to the 'scope' >> > field, the object is "normal" (i.e. not a reference). >> >> Hmm, can I see the code? > Here's my constructor function definition: > zend_internal_function php_python_constructor_function = { > ZEND_INTERNAL_FUNCTION, /* type */ > "python", /* function_name */ > &python_class_entry, /* scope */ > 0, /* fn_flags */ > NULL, /* prototype */ > 0, /* num_args */ > NULL, /* arg_info */ > 0, /* pass_rest_by_reference */ > ZEND_FN(python_new) /* handler */ > }; > I use this function as part of my class initialization: > INIT_CLASS_ENTRY(python_class_entry, "python", NULL); > python_class_entry.create_object = python_object_create; > python_class_entry.constructor = (union _zend_function *)&php_python_constructor_function; > zend_register_internal_class(&python_class_entry TSRMLS_CC); > And I return the 'constructor' value from my 'constructor_get' > handler: > static union _zend_function * > python_constructor_get(zval *object TSRMLS_DC) > { > php_python_object *obj = PIP_FETCH(object); > return obj->ce->constructor; > } > If I specify NULL for the 'scope' field, I end up with a second > reference to the new object. > I don't know if that's intentional or a bug. I'm still getting > familiar with the new object model code. Why do you make it so complicated? You could imply provide a list of methods for your objects and register them with the third parameter of INIT_CLASS_ENTRY() macro. That would handle the constructor correct. Also you should name the constructor '__construct' instead of 'python' because the former is the prefered way for ZE2. -- Best regards, Marcus mailto:helly@php.net