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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php