# parsing break and continue statements

- Thread: https://externals.io/message/54239
- Original archive: https://news-web.php.net/php.internals/54239
- Started by Kiyoto Tamura on 2011-07-28T23:10:35+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #54239 — Kiyoto Tamura — 2011-07-28T23:10:35+00:00

URL: https://externals.io/message/54239#54239

Hi,

I am new to the PHP internals, and I was just looking through the code
related to parsing break/continue statements. It looks that as of PHP
5.4, Zend/zend_language_parser.y accepts both "T_BREAK expr" and
"T_CONTINUE expr" and check to make sure "expr" is a positive integer
in the function zend_do_brk_cont. Doesn't it make more sense to
replace "T_BREAK expr" with  "T_BREAK <positive integer>" (the same
goes for the continue statement)?

Thanks in advance!

kiyoto

---

## #54240 — johannes@schlueters.de — 2011-07-28T23:53:30+00:00

URL: https://externals.io/message/54239#54240 · In reply to: #54239

> Hi,
> 
> I am new to the PHP internals, and I was just looking through the code
> related to parsing break/continue statements. It looks that as of PHP
> 5.4, Zend/zend_language_parser.y accepts both "T_BREAK expr" and
> "T_CONTINUE expr" and check to make sure "expr" is a positive integer
> in the function zend_do_brk_cont. Doesn't it make more sense to
> replace "T_BREAK expr" with  "T_BREAK <positive integer>" (the same
> goes for the continue statement)?

 `T_BREAK` expr  allows things like

   $foo = rand(...);
   break $foo;

but we've dropped that for performance reasons in 5.4.

johannes

> Thanks in advance!
> 
> kiyoto

---

## #54243 — Kiyoto Tamura — 2011-07-29T02:24:59+00:00

URL: https://externals.io/message/54239#54243 · In reply to: #54240

Hi Johannes,

Thanks for your reply :) What I meant was that why does the parser
still accept any expression after T_BREAK/CONTINUE and defer the error
check to zend_do_brk_cont? Isn't it clearer to only accept if the
expression following T_BREAK/CONTINUE is a positive integer (if there
is any expression at all)?

Kiyoto

2011/7/28 Johannes Schlüter <johannes@schlueters.de>:
> 
> > […]
>
> `T_BREAK` expr  allows things like
>
>   $foo = rand(...);
>   break $foo;
>
> but we've dropped that for performance reasons in 5.4.
>
> johannes
>
> > […]

---

## #54312 — Jan Dolecek — 2011-08-03T12:26:16+00:00

URL: https://externals.io/message/54239#54312 · In reply to: #54243

I guess to get a clear error message, because this is a BC change.
Many people would wonder why working scripts are causing parse errors
after upgrade of php. Makes sense to have error messages as clear as
possible ;)

Jan Dolecek
juzna.cz@gmail.com



2011/7/29 Kiyoto Tamura <owenestea@gmail.com>:
> Hi Johannes,
>
> Thanks for your reply :) What I meant was that why does the parser
> still accept any expression after T_BREAK/CONTINUE and defer the error
> check to zend_do_brk_cont? Isn't it clearer to only accept if the
> expression following T_BREAK/CONTINUE is a positive integer (if there
> is any expression at all)?
>
> Kiyoto
>
> 2011/7/28 Johannes Schlüter <johannes@schlueters.de>:
> > […]
