Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43298 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97378 invoked from network); 10 Mar 2009 20:03:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2009 20:03:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 85.214.94.56 as permitted sender) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 85.214.94.56 aixcept.net Linux 2.6 Received: from [85.214.94.56] ([85.214.94.56:33292] helo=h1149922.serverkompetenz.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F7/A7-61255-C87C6B94 for ; Tue, 10 Mar 2009 15:03:26 -0500 Received: from dhcp-172-26-94-64.nyc.corp.google.com (unknown [72.14.228.89]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by h1149922.serverkompetenz.net (Postfix) with ESMTP id 16DEF11F71E; Tue, 10 Mar 2009 21:03:20 +0100 (CET) Date: Tue, 10 Mar 2009 21:03:19 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <257144875.20090310210319@marcus-boerger.de> To: Frankie Dintino CC: internals@lists.php.net In-Reply-To: <2009031012193216807-fdintino@nflcorg> References: <2009031012193216807-fdintino@nflcorg> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Cloning of objects passed as parameters From: helly@php.net (Marcus Boerger) Hello Frankie, Tuesday, March 10, 2009, 5:19:32 PM, you wrote: > I'm writing a PHP class with a method that has to be passed a > DOMDocument object, and it needs to retain that object throughout the > life of its instantiation. However, the (dom_object *) returned from > zend_parse_method_parameters is just a pointer to the passed object, > and so it disappears when the original document is unset or goes out of > scope. How would one go about cloning the DOMDocument to save in the > class's struct? > example: > ZEND_METHOD(xydelta, setStartDocument) { > zval *id, *doc = NULL; > xydelta_object *intern; > if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), > "Oo", &id, xydelta_ce, &doc) == FAILURE) { > RETURN_FALSE; > } > intern = (xydelta_object *)zend_object_store_get_object(id TSRMLS_CC); > if (intern != NULL) { > // Error checking removed for brevity... > // ... > // This pointer cannot be accessed once the object that was used as > the first parameter goes out of scope > intern->libxml_start_doc = (php_libxml_node_object *) > zend_object_store_get_object(doc TSRMLS_CC); > } > } DOMDocuments are reference counted, hence zou can simplz increase their refcount when storing the connection and delete the ref when dropping the connection, probably in your destructor. Best regards, Marcus