Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56164 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71613 invoked from network); 8 Nov 2011 14:26:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Nov 2011 14:26:50 -0000 Authentication-Results: pb1.pair.com smtp.mail=cpriest@zerocue.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cpriest@zerocue.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zerocue.com designates 74.115.204.54 as permitted sender) X-PHP-List-Original-Sender: cpriest@zerocue.com X-Host-Fingerprint: 74.115.204.54 relay-hub202.domainlocalhost.com Windows 2000 SP2+, XP SP1 (seldom 98 4.10.2222) Received: from [74.115.204.54] ([74.115.204.54:30408] helo=relay-hub202.domainlocalhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/30-04521-72C39BE4 for ; Tue, 08 Nov 2011 09:26:49 -0500 Received: from MBX206.domain.local ([169.254.6.220]) by HUB202.domain.local ([74.115.204.52]) with mapi id 14.01.0289.001; Tue, 8 Nov 2011 09:26:46 -0500 To: "internals@lists.php.net" Thread-Topic: Accessors Parsing Thread-Index: AcyeH0P0XNnmcjK5TNG7H6R1PFHUjg== Date: Tue, 8 Nov 2011 14:26:44 +0000 Message-ID: <9570D903A3BECE4092E924C2985CE485398008EA@MBX206.domain.local> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.64.21] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Accessors Parsing From: cpriest@zerocue.com (Clint M Priest) Working to implement Getter/Setter Accessor syntax as per https://wiki.php.= net/rfc/propertygetsetsyntax but brand new to php internals development. I was planning on having the parser define methods on the class for the get= ter/setter such as __getHours() and __setHours() and then have those functi= ons called in leiu of __get() if they are defined, does that seem like a re= asonable strategy for this? More specific problems on the parser side of things, here is what I have no= w: getter_setter_declarations: getter_declaration setter_declaration | setter_declaration getter_declaration | setter_declaration | getter_declaration | /* empty */ ; getter_declaration: method_modifiers T_GET { zend_do_begin_function_declaration(&$2, &$$, 1, ZEND_RETURN_VAL, &$1 TS= RMLS_CC); } '{' inner_statement_list '}' { /******** $$ !=3D Hours Here!! ***************/ zend_do_abstract_method(&$$, &$1, &$4 TSRMLS_CC); zend_do_end_function_d= eclaration(&$2 TSRMLS_CC); } setter_declaration: T_SET '{' inner_statement_list '}' class_variable_declaration: T_VARIABLE { $$ =3D $1; /**** Capture variable name ****/ } '{' getter_se= tter_declarations '}' | class_variable_declaration ',' T_VARIABLE { zend_do_declare_property= (&$3, NULL, CG(access_type) TSRMLS_CC); } | class_variable_declaration ',' T_VARIABLE '=3D' static_scalar { zend_do_= declare_property(&$3, &$5, CG(access_type) TSRMLS_CC); } | T_VARIABLE { zend_do_declare_property(&$1, NULL, CG(access_type) TS= RMLS_CC); } | T_VARIABLE '=3D' static_scalar { zend_do_declare_property(&$1, &$3, CG(a= ccess_type) TSRMLS_CC); } ; I'm just working on the getter now.=20 1) I am able to get the T_VARIABLE name passed through to the zend_do_begi= n_function() using $$ however $$ is no longer correctly set by zend_do_abst= ract_method(). What would be a more appropriate way to store the variable = znode? I see there are a number of stacks in the compiler_globals, would u= sing one of those or creating a new one be appropriate? 1.1) Alternatively to #1, is there a way to access the T_VARIABLE znode fr= om the zend_do_begin_function_declaration() line? (Reach re patterns from= previous/prior matches/lines) 2) I am having trouble with building the function name (2nd param to zend_= do_begin_function) since that function needs to have a znode as the input. = I could stuff code in here to concat the strings together and build a znod= e but since there is sparsely any real code in this file I hesitate to do s= o. Any recommendations here?=20 3) An interesting situation with the above code is that the function is dec= lared and is seen through a ReflectionClass() but calling it indicates that= the function does not exist, I think that is because $$ was cleared/change= d by the time zend_do_abstract() is called, is this something I should add = a check for? (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 Seconds =3D $Seconds; } public $Hours { get { return $this->Seconds / 3600; } /* set { $this->Seconds =3D $value * 3600; } // The variable $value holds = the incoming value to be "set"*/ }; } $o =3D new TimePeriod(3600); echo $o->Seconds."\r\n"; echo $o->Hours()."\r\n"; ?>