Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72980 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73068 invoked from network); 6 Mar 2014 17:26:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Mar 2014 17:26:18 -0000 Authentication-Results: pb1.pair.com header.from=oneil@saxonica.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=oneil@saxonica.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain saxonica.com from 217.69.47.236 cause and error) X-PHP-List-Original-Sender: oneil@saxonica.com X-Host-Fingerprint: 217.69.47.236 uk1rly2283.eechost.net Linux 2.6 Received: from [217.69.47.236] ([217.69.47.236:44674] helo=uk1rly2283.eechost.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/04-52599-7BFA8135 for ; Thu, 06 Mar 2014 12:26:16 -0500 Received: from [82.152.109.199] (helo=[192.168.0.106]) by uk1rly2283.eechost.net with esmtpa (Exim 4.72) (envelope-from ) id 1WLc4C-0007VV-0d; Thu, 06 Mar 2014 17:26:44 +0000 Message-ID: <5318AFB1.3050305@saxonica.com> Date: Thu, 06 Mar 2014 17:26:09 +0000 Organization: Saxonica User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Chris Wright CC: internals@lists.php.net References: <53189E57.1010501@saxonica.com> In-Reply-To: Content-Type: multipart/alternative; boundary="------------060600010307050606000503" X-Auth-Info: oneil@saxonica.com (plain) Subject: Re: [PHP-DEV] using Zend: extensions module: Accessing instance data internally From: oneil@saxonica.com (O'Neil Delpratt) --------------060600010307050606000503 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 06/03/14 17:08, Chris Wright wrote: > On 6 March 2014 16:12, O'Neil Delpratt wrote: >> Hi, >> >> I have two created two php objects in my extension module called >> SaxonProcessor and XdmValue: >> >> struct saxonProcessor_object { >> zend_object std; >> SaxonProcessor * saxonProcessor; >> XsltProcessor *xsltProcessor; >> XQueryProcessor *xqueryProcessor; >> XdmValue * xdmValue; >> char * stylesheetFile; >> char * stylesheetStr; >> char * queryFile; >> char * queryStr; >> }; >> >> >> struct xdmValue_object { >> zend_object std; >> XdmValue * xdmValue; >> }; >> >> >> In the XdmValue_object I need to pass internally the C++ SaxonProcessor >> object in the saxonProcessor_object, but I am not sure how to do this >> because in the XdmValue constructor the getThis() method allows me to gain >> access to the xdmValue_object struct: >> >> xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object( >> getThis() TSRMLS_CC); >> >> Any ideas? > I'm not 100% sure what you are asking here so if this comes off as > patronising then I'm sorry :-P > > It sounds like what you have is simply a classic circular reference > thru dependency injection problem. A good paradigm for solving this is > to have one object create the other and inject itself in the process. > > Can you explain the userland PHP API you are trying to create here? > >From reading the documentation for Saxon I can't see why a Processor > would have a member which is an XdmValue or, to be honest, vice versa. > They both seem to operate independently of each other. > > Thanks, Chris > The problem is the SaxonProcessor is the main class stores configuration information shared across all the processors, for example a namepool is cached. The work around which I have now tried and it works is to create the XdmValue via the the SaxonProcessor class as a factory function and not independently. A separate issue I have is how to maintain thread safety in a NTS version of PHP. The SaxonProcessor contains some third-party dependency library which restricts more than one instance created at anyone time. I notice that some time PHP requests are not closed before another one starts which results in the a crash of the library. Thanks and kind regards, O'Neil -- O'Neil Delpratt Software Developer, Saxonica Limited Email: oneil@saxonica.com Tel: +44 118 946 5894 Web: http://www.saxonica.com Saxonica Community Site: http://dev.saxonica.com Saxonica Bug tracking System: https://saxonica.plan.io/ --------------060600010307050606000503--