Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54296 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96848 invoked from network); 2 Aug 2011 21:03:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Aug 2011 21:03:35 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.42 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.161.42 mail-fx0-f42.google.com Received: from [209.85.161.42] ([209.85.161.42:51235] helo=mail-fx0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/10-30104-626683E4 for ; Tue, 02 Aug 2011 17:03:34 -0400 Received: by fxe23 with SMTP id 23so219809fxe.29 for ; Tue, 02 Aug 2011 14:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=FMAS6T4/L+DLnCAgEiWjbCC1eX6le0/mxr3N+3xCT5Y=; b=eVq+hIX2HceqSItwUpbhIgVpbY8jOiFMSdoClYOh0IkDHE8uhBwyw3kAAQcxBepWGt SkSbdukQtDJSdWMCa09tlvDcK66BC1kwpDBg2mej4JaMopu4CxwTq4/Hk8AwPjyGd40X AoHVCowhsPSbG2ucZW2tEjyYogrJhzrUKBxMY= MIME-Version: 1.0 Received: by 10.204.34.130 with SMTP id l2mr1958245bkd.170.1312319010390; Tue, 02 Aug 2011 14:03:30 -0700 (PDT) Sender: ekneuss@gmail.com Received: by 10.204.66.20 with HTTP; Tue, 2 Aug 2011 14:03:30 -0700 (PDT) In-Reply-To: <4E385892.9090106@gmail.com> References: <4E385892.9090106@gmail.com> Date: Tue, 2 Aug 2011 23:03:30 +0200 X-Google-Sender-Auth: YI-k1Kgv6Pjv-bICibORVQt4XBQ Message-ID: To: Flavius Aspra Cc: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [Q] references and objects From: colder@php.net (Etienne Kneuss) Hello, On Tue, Aug 2, 2011 at 22:05, Flavius Aspra wrote: > I have a zval *obj holding an object of class B, which I then add to an > array member of another object of class A. Then I create a new instance > *obj2 of class B, to which I want to add a reference to *obj. How would I > best go about it? > > So A works as a "pool" of B's, and B's may reference to each other. > > Please tell me key functions and macros to use to accomplish specifically > this thing, as the API is quite new to me. > > I have thought about setting Z_SET_ISREF_P() manually, but what else would I > need? From my understanding, I'd still need a new zval* for that. Any other > better ways? You generally don't want to use references. Rather, you can keep the same zval* pointer as long as you increment/decrement its refcount (Z_ADDREF_P/zval_ptr_dtor) so that it correctly keeps track of how many pointers are pointing to it. Unless I misunderstood what you're trying to do, it's that easy. Best, > > Regards, > Flavius > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Etienne Kneuss http://www.colder.ch