Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:20619 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74953 invoked by uid 1010); 27 Nov 2005 01:55:59 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 74938 invoked from network); 27 Nov 2005 01:55:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Nov 2005 01:55:59 -0000 X-Host-Fingerprint: 68.215.62.134 adsl-215-62-134.mia.bellsouth.net Received: from ([68.215.62.134:25486] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 7A/3C-56276-F2219834 for ; Sat, 26 Nov 2005 20:55:59 -0500 To: internals@lists.php.net,Alan Knowles Message-ID: <43891229.5040309@gmail.com> Date: Sat, 26 Nov 2005 20:55:53 -0500 User-Agent: Mozilla Thunderbird 1.0.7-1.1.fc4 (X11/20050929) X-Accept-Language: en-us, en MIME-Version: 1.0 CC: Marcus Boerger , Sebastian Kugler , =?ISO-8859-1?Q?Oliver_Gr=E4tz?= References: <7.0.0.16.2.20051124161240.0573e640@zend.com> <200511251419.56809.pookey@pookey.co.uk> <57.B8.56276.65B27834@pb1.pair.com> <73998811.20051125204046@marcus-boerger.de> <438782C6.80008@gmail.com> <43878626.5060300@lerdorf.com> <512771162.20051125225926@marcus-boerger.de> <6B.D6.56276.154E7834@pb1.pair.com> <1638013035.20051126122138@marcus-boerger.de> <818043770511260446q14947ceai64c78d146e632b71@mail.gmail.com> <1845355691.20051126135605@marcus-boerger.de> <1133054453.15210.23.camel@alanportable2.hklc.com> In-Reply-To: <1133054453.15210.23.camel@alanportable2.hklc.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 68.215.62.134 Subject: Re: [PHP-DEV] Re: PHP 5.1 (Or How to break tousands of apps outthere) From: jrhernandez05@gmail.com (Jessie Hernandez) Hello Alan, Alan Knowles wrote: > this is not entirely true: > > token : "[WS]+?[WS]+" == conditional if seperater 1 > token : "[WS]+:[WS]+" == conditional if seperater 2 > token : ":[WS]+" == case/ if ($a == 5): / else: / endif; > token : ":" == namespace stuff... > > eg. adding whitespace around the " : " and declaring that a token, > rather than creating a token for the whitespace it, should work?? > > Regards > Alan > Yes, this would work, but would also potentially break lots of scripts out there, and I already see resistance for this. NOW, this can also be done like the reference change, and accept both forms. For example, the following would run OK but it'll generate an E_STRICT: $a = true?$a:$b; The following would produce the same result, but without an E_STRICT: $a = true ? $a : $b; This is easy to do in zend_language_parser.y: --------------- expr_without_variable: | expr '?' { zend_error(E_STRICT, "Ternary operators without surrounding spaces are deprecated!"); zend_do_begin_qm_op(&$1, &$2 TSRMLS_CC); } expr ':' { zend_error(E_STRICT, "Ternary operators without surrounding spaces are deprecated!"); zend_do_qm_true(&$4, &$2, &$5 TSRMLS_CC); } expr { zend_do_qm_false(&$$, &$7, &$2, &$5 TSRMLS_CC); } | expr ' ? ' { zend_do_begin_qm_op(&$1, &$2 TSRMLS_CC); } expr ' : ' { zend_do_qm_true(&$4, &$2, &$5 TSRMLS_CC); } expr { zend_do_qm_false(&$$, &$7, &$2, &$5 TSRMLS_CC); } --------------- We can also encourage parentheses instead of spaces (though spaces are less intrusive). I quote from http://www.php.net/manual/en/language.operators.php: "The third group is the ternary operator: ?:. It should be used to select between two expressions depending on a third one, rather than to select two sentences or paths of execution. Surrounding ternary expressions with parentheses is a very good idea." Regards, Jessie Hernandez