Re: C++ Objects and Resource Lists....

From: Date: Mon, 21 Aug 2000 20:57:54 +0000
Subject: Re: C++ Objects and Resource Lists....
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-30139@lists.php.net to get a copy of this message
I'm not sure I understand. You get back a reference. Is that reference valid forever? Basically, you can store a pointer to this reference, and dereference it as long as the object is intact: C++/pseudo code: extern Object &GetObject(); Object &Foo = GetObject(); Store(&Foo, some_table, "somekey"); ... pFoo = Get(some_table, "somekey"); pFoo->method(); If that doesn't work, it means the object itself got destructed and is no longer valid. You can (should :) try to figure out where that happens in order to properly understand what's going on, and that you're not leaking memory. If this behavior is correct, you should either figure out a way to keep the object alive as long as you use it, or copy it before you store it. If I didn't get it, please explain again :) Zeev At 23:42 21/08/2000, PHP Developers List wrote:
        I have a strange question and I'm not exactly sure how to ask it
so here goes. I'm writing a PHP extension as a DSO which will provide wrapper objects for the Xerces XML parser (from xml.apache.org). The Xerces parser is a DSO that is written in C++. Now, I have most of this done already. I can call the Xerces stuff from the PHP extension parse the XML files and I've written wrappers for most of the common classes and "get" methods. But I had to hack it a little and I'm afraid that the hack is going to prevent me from writting wrappers for the "set" methods.
        When I parse a file I get back a reference to a
"DOM_Document" object. I can get the address of that object and store that in a resource list. I have a PHP Object with a "hidden" attribute that keeps track of the resource number. When any of the wrapper methods are called, I look up the resource and get the reference to the DOM_Document and I can call the appropriate method. Now, here's where I'm having a problem. There are a number of methods that return references to other objects (references, not pointer). For instance, getFirstChild(). This returns the first child node (DOM_Node object) under the current node. If I call this on the DOM_Document object, I cannot store the address of the DOM_Node (I get segfaults when I try to reference them after pulling them back from a resource) I get back, I have to clone this node locally by passing it through the copy constructor for DOM_Node. I really don't want to do this. I would like to be able to store a reference to each node so that they can be changed and then a new Document could be exported. Or, a document could be built from scratch.
        Anyway, if you have ideas, or if you want to just ask me what the
heck I'm talking about... please let me know. Thanks, Bob -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- Zeev Suraski <zeev@zend.com> http://www.zend.com/

« previous php.dev (#30139) next »