Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:31358 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26590 invoked by uid 1010); 1 Aug 2007 23:59:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 26575 invoked from network); 1 Aug 2007 23:59:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Aug 2007 23:59:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=andi@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=andi@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 63.205.162.114 as permitted sender) X-PHP-List-Original-Sender: andi@zend.com X-Host-Fingerprint: 63.205.162.114 unknown Windows 2000 SP4, XP SP1 Received: from [63.205.162.114] ([63.205.162.114:62295] helo=us-ex1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/F0-15960-36E11B64 for ; Wed, 01 Aug 2007 19:59:31 -0400 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Wed, 1 Aug 2007 16:59:28 -0700 Message-ID: <698DE66518E7CA45812BD18E807866CE7C10BB@us-ex1.zend.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] Fix inconsistencies in OO calls Thread-Index: AcfTai7z4vsTjcofQ/WYib9ABX9+wwBDhe7Q References: <46AE49B3.2070100@php.net> <1185883035.23889.31.camel@johannes.nop> To: =?iso-8859-1?Q?Johannes_Schl=FCter?= , "Etienne Kneuss" Cc: , "Ilia Alshanetsky" Subject: RE: [PHP-DEV] Fix inconsistencies in OO calls From: andi@zend.com ("Andi Gutmans") This is not really a fix. When we worked on PHP 5 we deliberately decided to relax on all the = weird dynamic constructs which didn't provide a lot of value for the = majority of use-cases. Of course the Reflection API was going to be the = way to do these dynamic things in future. It would also simplify the = engine's code. The reason why those first constructs work were for BC = reasons. We didn't want to break existing code but wanted to not add on = top of this. While it may feel inconsistent I still prefer the existing path. Maybe = for PHP 6 we can even make an E_STRICT message for the old way which = refers you to the Reflection API? Andi=20 > -----Original Message----- > From: Johannes Schl=FCter [mailto:johannes@php.net]=20 > Sent: Tuesday, July 31, 2007 4:57 AM > To: Etienne Kneuss > Cc: internals@lists.php.net; Ilia Alshanetsky > Subject: Re: [PHP-DEV] Fix inconsistencies in OO calls >=20 > Hi Etienne, >=20 > On Mon, 2007-07-30 at 22:27 +0200, Etienne Kneuss wrote: > > Hello, > >=20 > > Currently, those are allowed: > >=20 > > new $classname; > > classname::$methodname(); > >=20 > > but those aren't: > >=20 > > $classname::foo(); > > $classname::CONST; > > $classname::$member; > >=20 > > Here is a patch for head that fixes those inconsistencies=20 > by extending=20 > > the language parser to support such syntax: >=20 > thanks for this fix. > Ilia, do you mind MFHing this fix before the next 5.2=20 > release? Then I'd commit it within the next days. >=20 > johannes >=20 > >=20 > http://patches.colder.ch/Zend/dynamic_static_calls.patch?marku p (patch=20 > > also attached) > >=20 > > Regards > >=20 > > plain text document attachment (dynamic_static_calls.patch) > > Index: Zend/zend_language_parser.y > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > RCS file: /repository/ZendEngine2/zend_language_parser.y,v > > retrieving revision 1.186 > > diff -u -p -r1.186 zend_language_parser.y > > --- Zend/zend_language_parser.y 27 Jul 2007 09:04:12=20 > -0000 1.186 > > +++ Zend/zend_language_parser.y 30 Jul 2007 20:28:41 -0000 > > @@ -649,6 +649,12 @@ function_call: > > | fully_qualified_class_name=20 > T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' {=20 > zend_do_begin_class_member_function_call(&$1, &$3 TSRMLS_CC); } > > function_call_parameter_list > > ')' { zend_do_end_function_call(NULL,=20 > &$$, &$6, 1, 1 TSRMLS_CC);=20 > > zend_do_extended_fcall_end(TSRMLS_C);} > > + | variable_class_name T_PAAMAYIM_NEKUDOTAYIM=20 > T_STRING '(' { zend_do_begin_class_member_function_call(&$1,=20 > &$3 TSRMLS_CC); } > > + function_call_parameter_list > > + ')' { zend_do_end_function_call(NULL,=20 > &$$, &$6, 1, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C);} > > + | variable_class_name T_PAAMAYIM_NEKUDOTAYIM=20 > variable_without_objects '(' {=20 > zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC);=20 > zend_do_begin_class_member_function_call(&$1, &$3 TSRMLS_CC); } > > + function_call_parameter_list > > + ')' { zend_do_end_function_call(NULL,=20 > &$$, &$6, 1, 1 TSRMLS_CC);=20 > > +zend_do_extended_fcall_end(TSRMLS_C);} > > | fully_qualified_class_name=20 > T_PAAMAYIM_NEKUDOTAYIM variable_without_objects '(' {=20 > zend_do_end_variable_parse(BP_VAR_R, 0 TSRMLS_CC);=20 > zend_do_begin_class_member_function_call(&$1, &$3 TSRMLS_CC); } > > function_call_parameter_list > > ')' { zend_do_end_function_call(NULL,=20 > &$$, &$6, 1, 1 TSRMLS_CC);=20 > > zend_do_extended_fcall_end(TSRMLS_C);} > > @@ -809,6 +815,11 @@ variable_without_objects: > > =20 > > static_member: > > fully_qualified_class_name T_PAAMAYIM_NEKUDOTAYIM=20 > > variable_without_objects { $$ =3D $3;=20 > zend_do_fetch_static_member(&$$,=20 > > &$1 TSRMLS_CC); } > > + | variable_class_name T_PAAMAYIM_NEKUDOTAYIM=20 > variable_without_objects { $$ =3D $3;=20 > zend_do_fetch_static_member(&$$, &$1 TSRMLS_CC); } > > +; > > + > > +variable_class_name: > > + reference_variable { zend_do_end_variable_parse(BP_VAR_R, 0=20 > > +TSRMLS_CC); $$=3D$1;} > > ; > > =20 > >=20 > > @@ -935,6 +946,7 @@ isset_variables: > > =20 > > class_constant: > > fully_qualified_class_name=20 > T_PAAMAYIM_NEKUDOTAYIM T_STRING {=20 > > zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT TSRMLS_CC); } > > + | variable_class_name T_PAAMAYIM_NEKUDOTAYIM=20 > T_STRING { zend_do_fetch_constant(&$$, &$1, &$3, ZEND_RT TSRMLS_CC); } > > ; > > =20 > > %% > > Index: tests/lang/041.phpt > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > RCS file: tests/lang/041.phpt > > diff -N tests/lang/041.phpt > > --- /dev/null 1 Jan 1970 00:00:00 -0000 > > +++ tests/lang/041.phpt 30 Jul 2007 20:28:41 -0000 > > @@ -0,0 +1,23 @@ > > +--TEST-- > > +Dynamic access of static members > > +--FILE-- > > + > +class A { > > + public static $b =3D 'foo'; > > +} > > + > > +$classname =3D 'A'; > > +$binaryClassname =3D b'A'; > > +$wrongClassname =3D 'B'; > > + > > +echo $classname::$b."\n"; > > +echo $binaryClassname::$b."\n"; > > +echo $wrongClassname::$b."\n"; > > + > > +?> > > +=3D=3D=3DDONE=3D=3D=3D > > +--EXPECTF-- > > +foo > > +foo > > + > > +Fatal error: Class 'B' not found in %s041.php on line %d > > Index: tests/lang/042.phpt > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > RCS file: tests/lang/042.phpt > > diff -N tests/lang/042.phpt > > --- /dev/null 1 Jan 1970 00:00:00 -0000 > > +++ tests/lang/042.phpt 30 Jul 2007 20:28:41 -0000 > > @@ -0,0 +1,22 @@ > > +--TEST-- > > +Dynamic access of constants > > +--FILE-- > > + > +class A { > > + const B =3D 'foo'; > > +} > > + > > +$classname =3D 'A'; > > +$binaryClassname =3D b'A'; > > +$wrongClassname =3D 'B'; > > + > > +echo $classname::B."\n"; > > +echo $binaryClassname::B."\n"; > > +echo $wrongClassname::B."\n"; > > +?> > > +=3D=3D=3DDONE=3D=3D=3D > > +--EXPECTF-- > > +foo > > +foo > > + > > +Fatal error: Class 'B' not found in %s042.php on line %d > > Index: tests/lang/043.phpt > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > RCS file: tests/lang/043.phpt > > diff -N tests/lang/043.phpt > > --- /dev/null 1 Jan 1970 00:00:00 -0000 > > +++ tests/lang/043.phpt 30 Jul 2007 20:28:41 -0000 > > @@ -0,0 +1,22 @@ > > +--TEST-- > > +Dynamic call for static methods > > +--FILE-- > > + > +class A { > > + static function foo() { return 'foo'; } } > > + > > +$classname =3D 'A'; > > +$binaryClassname =3D b'A'; > > +$wrongClassname =3D 'B'; > > + > > +echo $classname::foo()."\n"; > > +echo $binaryClassname::foo()."\n"; > > +echo $wrongClassname::foo()."\n"; > > +?> > > +=3D=3D=3DDONE=3D=3D=3D > > +--EXPECTF-- > > +foo > > +foo > > + > > +Fatal error: Class 'B' not found in %s043.php on line %d > > Index: tests/lang/044.phpt > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > RCS file: tests/lang/044.phpt > > diff -N tests/lang/044.phpt > > --- /dev/null 1 Jan 1970 00:00:00 -0000 > > +++ tests/lang/044.phpt 30 Jul 2007 20:28:41 -0000 > > @@ -0,0 +1,30 @@ > > +--TEST-- > > +Dynamic call for static methods dynamically named > > +--FILE-- > > + > +class A { > > + static function foo() { return 'foo'; } } > > +$classname =3D 'A'; > > +$binaryClassname =3D b'A'; > > +$wrongClassname =3D 'B'; > > + > > +$methodname =3D 'foo'; > > +$binaryMethodname =3D b'foo'; > > + > > +echo $classname::$methodname()."\n"; > > +echo $classname::$binaryMethodname()."\n"; > > + > > +echo $binaryClassname::$methodname()."\n"; > > +echo $binaryClassname::$binaryMethodname()."\n"; > > + > > +echo $wrongClassname::$binaryMethodname()."\n"; > > +?> > > +=3D=3D=3DDONE=3D=3D=3D > > +--EXPECTF-- > > +foo > > +foo > > +foo > > +foo > > + > > +Fatal error: Class 'B' not found in %s044.php on line %d > >=20 > > -- > > PHP Internals - PHP Runtime Development Mailing List To=20 > unsubscribe,=20 > > visit: http://www.php.net/unsub.php >=20 > -- > PHP Internals - PHP Runtime Development Mailing List To=20 > unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20