Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56165 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85749 invoked from network); 8 Nov 2011 16:52:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Nov 2011 16:52:10 -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.214.42 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:51711] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A5/80-17035-73E59BE4 for ; Tue, 08 Nov 2011 11:52:08 -0500 Received: by bkbzt4 with SMTP id zt4so633515bkb.29 for ; Tue, 08 Nov 2011 08:52:03 -0800 (PST) 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 :content-transfer-encoding; bh=1Wc0Tgmv6m8bfnMMdJvh8ZcJbA0pyRdETvrZk53KUlM=; b=O9Y1bkl6tU5YxkdGzWBsyXNpMPqHpLPjTOKAOHHYCwt8PX1LtbC4JfAsb3e7aeenLC p8ERh7N6cCz508Vok1iQaVLca6BuQK9vRPcwrEGe87W+GYk1wljt3tFWVQ9ycR6VIDrX QvWEvbXTqDSLkT0cNpGutwzlk6Fnz4aDwEbhU= MIME-Version: 1.0 Received: by 10.204.49.23 with SMTP id t23mr23452072bkf.60.1320771121795; Tue, 08 Nov 2011 08:52:01 -0800 (PST) Sender: ekneuss@gmail.com Received: by 10.205.37.205 with HTTP; Tue, 8 Nov 2011 08:52:01 -0800 (PST) In-Reply-To: <9570D903A3BECE4092E924C2985CE485398008EA@MBX206.domain.local> References: <9570D903A3BECE4092E924C2985CE485398008EA@MBX206.domain.local> Date: Tue, 8 Nov 2011 17:52:01 +0100 X-Google-Sender-Auth: _BxxcH7bc6nwTn5Z7zX0Ac2MLlE Message-ID: To: Clint M Priest Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Accessors Parsing From: colder@php.net (Etienne Kneuss) Hi, quick note: By introducing T_GET and T_SET, you disable people the ability to name any function/method "set" or "get", which I'm sure many people used. You should rather keep to T_STRING and check it's value. Best, On Tue, Nov 8, 2011 at 15:26, Clint M Priest wrote: > Working to implement Getter/Setter Accessor syntax as per https://wiki.ph= p.net/rfc/propertygetsetsyntax but brand new to php internals development. > > I was planning on having the parser define methods on the class for the g= etter/setter such as __getHours() and __setHours() and then have those func= tions called in leiu of __get() if they are defined, does that seem like a = reasonable strategy for this? > > More specific problems on the parser side of things, here is what I have = now: > > getter_setter_declarations: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0getter_declaration > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0setter_declaration > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 setter_declaration > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0getter_declaration > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 setter_declaration > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 getter_declaration > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 /* empty */ > ; > > getter_declaration: > =C2=A0 =C2=A0 =C2=A0 =C2=A0method_modifiers T_GET > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ zend_do_begin_fu= nction_declaration(&$2, &$$, 1, ZEND_RETURN_VAL, &$1 TSRMLS_CC); } > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0'{' inner_statement_list '}' > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0{ /******** $$ != =3D Hours Here!! ***************/ > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 zend_do_abstract_= method(&$$, &$1, &$4 TSRMLS_CC); zend_do_end_function_declaration(&$2 TSRML= S_CC); } > > setter_declaration: > =C2=A0 =C2=A0 =C2=A0 =C2=A0T_SET '{' inner_statement_list '}' > > class_variable_declaration: > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0T_VARIABLE { $$ = =3D $1; /**** Capture variable name ****/ } '{' getter_setter_declarations = '}' > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 class_variable_declarat= ion ',' T_VARIABLE =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 { zend_do_declare_property(&$3, NULL, CG(access_type) TSRMLS_CC); } > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 class_variable_declarat= ion ',' T_VARIABLE '=3D' static_scalar =C2=A0 =C2=A0 { zend_do_declare_prop= erty(&$3, &$5, CG(access_type) TSRMLS_CC); } > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 T_VARIABLE =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0{ zend_do_declare_property(&$1, NULL, CG(access_type) TSRMLS_CC); } > =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0 =C2=A0 T_VARIABLE '=3D' static= _scalar =C2=A0 =C2=A0{ zend_do_declare_property(&$1, &$3, CG(access_type) T= SRMLS_CC); } > ; > > I'm just working on the getter now. > > =C2=A01) I am able to get the T_VARIABLE name passed through to the zend_= do_begin_function() using $$ however $$ is no longer correctly set by zend_= do_abstract_method(). =C2=A0What would be a more appropriate way to store t= he variable znode? =C2=A0I see there are a number of stacks in the compiler= _globals, would using one of those or creating a new one be appropriate? > > =C2=A01.1) Alternatively to #1, is there a way to access the T_VARIABLE z= node from the zend_do_begin_function_declaration() line? =C2=A0 (Reach re p= atterns from previous/prior matches/lines) > > 2) =C2=A0I am having trouble with building the function name (2nd param t= o zend_do_begin_function) since that function needs to have a znode as the = input. =C2=A0I could stuff code in here to concat the strings together and = build a znode but since there is sparsely any real code in this file I hesi= tate to do so. =C2=A0Any recommendations here? > > 3) An interesting situation with the above code is that the function is d= eclared and is seen through a ReflectionClass() but calling it indicates th= at the function does not exist, I think that is because $$ was cleared/chan= ged by the time zend_do_abstract() is called, is this something I should ad= d a check for? =C2=A0(Calling zend_do_abstract() with a function name that = was not previously seen via zend_do_begin_function_declaration()) > > For reference, here is the PHP test class I am using: > > #!/opt/trunk/sapi/cli/php > class TimePeriod { > > =C2=A0 =C2=A0 =C2=A0 =C2=A0public $Seconds; > > =C2=A0 =C2=A0 =C2=A0 =C2=A0public function __construct($Seconds) { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0$this->Seconds =3D= $Seconds; > =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0public $Hours { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0get { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0return $this->Seconds / 3600; > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} > =C2=A0 =C2=A0 =C2=A0 =C2=A0/* =C2=A0 =C2=A0 =C2=A0set { $this->Seconds = =3D $value * 3600; } // The variable $value holds the incoming value to be = "set"*/ > =C2=A0 =C2=A0 =C2=A0 =C2=A0}; > } > > $o =3D new TimePeriod(3600); > > echo $o->Seconds."\r\n"; > echo $o->Hours()."\r\n"; > > ?> > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 Etienne Kneuss http://www.colder.ch