Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59448 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97442 invoked from network); 7 Apr 2012 23:12:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2012 23:12:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=yader.hernandez@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yader.hernandez@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: yader.hernandez@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:37981] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/90-29109-1C9C08F4 for ; Sat, 07 Apr 2012 19:12:01 -0400 Received: by obbeh20 with SMTP id eh20so4816385obb.29 for ; Sat, 07 Apr 2012 16:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=C3I10ljhURBt0vhKE+ylFQYhdTjI0Moqid4nb/u/O/Y=; b=j3+kdBLdo70+qEnqZ9N37qSOuy8FAF602yXXIaG6gdQAQvd3LJYdmi4vbTBOIbK7dO J8yfQdnFc9BGLPzx7Py1NRA+td3oT6bLwLhXS4WCSa7PfNGENfNbrBNs+prFjQwMbwZQ oeAq3b5IsTtPMQPfqjrBxpQmhou6RbBMef2SJw69XMMSqMidAc9vZ6gnfLS9w1DlYr1w FWee6pz3pInWWsxeOw9NOtno3hCye1qYFa7HjlZcCIcmg7EzNusUJj1q+ysQ8zLUy+yW 7PWq/5FgfuzOEYE0u9poN1DEBb9KrG8btZRpW7PWbGXrAjOkYdc7OTBxlZfoicqYcqtW Oohg== MIME-Version: 1.0 Received: by 10.60.28.137 with SMTP id b9mr3594073oeh.57.1333840318690; Sat, 07 Apr 2012 16:11:58 -0700 (PDT) Sender: yader.hernandez@gmail.com Received: by 10.60.147.199 with HTTP; Sat, 7 Apr 2012 16:11:58 -0700 (PDT) In-Reply-To: References: <1333834026.4220.6.camel@guybrush> Date: Sat, 7 Apr 2012 16:11:58 -0700 X-Google-Sender-Auth: P9Sb3IrVvRNoHqH4S5bnv95HNAQ Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=e89a8ff1c4ae61f3a304bd1ee650 Subject: Re: [PHP-DEV] how do you create a private property as an array in a class From: proxilabs@gmail.com (Matthew Hernandez) --e89a8ff1c4ae61f3a304bd1ee650 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 wrot= e: > 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 ca= n > manipulate *array ? Having a private variable would mean calling getThis= () > 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=FCter 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 or >> a debugger you could implement a debug_info hook. >> >> johannes >> >> >> > --e89a8ff1c4ae61f3a304bd1ee650--