Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59450 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13537 invoked from network); 8 Apr 2012 03:43:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2012 03:43:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:59702] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/B2-29109-C59018F4 for ; Sat, 07 Apr 2012 23:43:24 -0400 Received: by vbjk13 with SMTP id k13so2086279vbj.29 for ; Sat, 07 Apr 2012 20:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:from:in-reply-to:mime-version:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=1gSTCSinQHlwM6tzYU7+BoKBuv8N5P6TP03Kv5OVih0=; b=OVC2qQF/pUljJdvKs5fnzkXTH720BxA9JRL3QNTC7qTA/WLnb1KFiygQ2Kol8KrvBE QH24dx9t7yRIWAvDIcJc+W5LNMpkg7TfSDN8pskAsqHqQvL/5hVzge5aBt7EByl4lkmR ulB4BUjqFd8zFlLuezjuwp4ofIzg5akhLAOt9BpjFYzjcjQTJZ9kaamOmEjzsQnaW3Lm KNdfgHWnKa1EEjnp4OiwMZUDbaoKnWUrkrp1yaKb4yTwk6D+N6Yr/hhtziIoDbj8ibPN 1XNJCahWUz4aEXCWJkv6Usitj4GeOXEm8NPNfQ01iAp1XX7b6ulEnPAz2GwwM0RY1q7y M54g== Received: by 10.220.154.2 with SMTP id m2mr1486789vcw.55.1333856601646; Sat, 07 Apr 2012 20:43:21 -0700 (PDT) References: <1333834026.4220.6.camel@guybrush> In-Reply-To: Mime-Version: 1.0 (1.0) Date: Sun, 8 Apr 2012 11:41:31 +0800 Message-ID: <2489245882729818767@unknownmsgid> To: Matthew Hernandez Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] how do you create a private property as an array in a class From: laruence@gmail.com (Xinchen Hui) hi=EF=BC=9A You can refer to ext spl array Thanks Sent from my iPhone =E5=9C=A8 2012-4-8=EF=BC=8C7:12=EF=BC=8CMatthew Hernandez =E5=86=99=E9=81=93=EF=BC=9A > Here's what I have so far: > > typedef struct _foo_class_object { > zend_object std; > zval *elements; > int size; > } foo_class_object; > > static foo_class_object *foo_class_object_ptr; > static zend_class_entry *foo_class_ptr; > > ZEND_METHOD(foo_class, __construct) { > foo_class_object_ptr =3D (foo_class_object > *)zend_object_store_get_object(getThis() TSRMLS_CC); > > array_init(foo_class_object_ptr->elements); > } > > ZEND_METHOD(foo_class, add) { > zval *this =3D getThis(); > zval *item; > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &item) =3D=3D > FAILURE) { > RETURN_FALSE; > } > > add_next_index_zval(foo_class_object_ptr->elements, item); > > RETURN_TRUE; > } > > However, this doesn't work. when you call FooClass::add it causes a > segfault. I'm sure I'm abusing something :) > > thx > > On Sat, Apr 7, 2012 at 2:38 PM, Matthew Hernandez wr= ote: > >> Hi Johannes, >> >> Yes I just found out that I should extend instead of the approach I was >> thinking about. >> >> So I created this: >> >> typedef struct _foo_object { >> zend_object std; >> zval *array; >> int size; >> } foo_object; >> >> So the question is how do I correctly pass foo_object around so that I c= an >> manipulate *array ? Having a private variable would mean calling getThi= s() >> and handling it that way would be trivial. >> >> Are there any examples I could see? I'm using the slides from your >> presentation in 2009 to help me. >> >> thanks >> >> On Sat, Apr 7, 2012 at 2:27 PM, Johannes Schl=C3=BCter wrote: >> >>> Hi, >>> >>> On Sat, 2012-04-07 at 11:23 -0700, Matthew Hernandez wrote: >>>> This is my first extension I'm working on. I'm trying to make a class >>>> available to the user space with 1 private property that is an array. >>> >>> The first question is: Why? - Why add the overhead of creating such an >>> array if it is private? In most cases it is better to extend the >>> zend_object in C (struct my_object { zend_object inner; type >>> some_data;}) to hold private data. If you want to show it in var_dump o= r >>> a debugger you could implement a debug_info hook. >>> >>> johannes >>> >>> >>> >>