Re: Re: PHP 5.1 (Or How to break tousands of apps outthere)

From: Date: Sun, 27 Nov 2005 01:55:53 +0000
Subject: Re: Re: PHP 5.1 (Or How to break tousands of apps outthere)
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-20619@lists.php.net to get a copy of this message
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

« previous php.internals (#20619) next »