# break/continue $var

- Thread: https://externals.io/message/50348
- Original archive: https://news-web.php.net/php.internals/50348
- Started by Dmitry Stogov on 2010-11-18T14:35:06+00:00
- Messages: 14
- 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

---

## #50348 — Dmitry Stogov — 2010-11-18T14:35:06+00:00

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

Hi,

Previously we decided to remove "break/continue $var" syntax.
I even implemented it in PHP6 brunch, however it wasn't backported into 
  trunk. Could I do it?

Thanks. Dmitry.

---

## #50349 — Derick Rethans — 2010-11-18T14:39:30+00:00

URL: https://externals.io/message/50348#50349 · In reply to: #50348

> Previously we decided to remove "break/continue $var" syntax.
> I even implemented it in PHP6 brunch, however it wasn't backported into
> trunk. Could I do it?

Is there a really good reason to remove it?

regards,
Derick
-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug

---

## #50356 — Ferenc Kovacs — 2010-11-18T16:03:55+00:00

URL: https://externals.io/message/50348#50356 · In reply to: #50349

> 
>
> > […]
>
> Is there a really good reason to remove it?
>

Should be, otherwise I can't see why would you decided to remove it in the
first place.
I think this was because you can do the same with the new shiny goto syntax,
but I'm just guessing here.

Tyrael

---

## #50357 — Patrick ALLAERT — 2010-11-18T16:20:08+00:00

URL: https://externals.io/message/50348#50357 · In reply to: #50349

2010/11/18 Derick Rethans <derick@php.net>:
> 
>
> > […]
>
> Is there a really good reason to remove it?

Not sure, but at least, it is in *your* release notes :-)
http://www.php.net/~derick/meeting-notes.html#break-var

---

## #50384 — Dmitry Stogov — 2010-11-19T14:06:47+00:00

URL: https://externals.io/message/50348#50384 · In reply to: #50349

without $var it would be possible to compile break/continue into 
ZEND_FREE/ZEND_SWITCH_FREE and ZEND_JMP.

I also thought it would allow to remove op_array->brk_cont_array 
completely, but it's also used for exception handling. :(

Thanks. Dmitry.



Derick Rethans wrote:
> 
> 
> > […]
> 
> Is there a really good reason to remove it?
> 
> regards,
> Derick

---

## #50388 — Tjerk Meesters — 2010-11-19T14:55:37+00:00

URL: https://externals.io/message/50348#50388 · In reply to: #50357

Reading those notes I'm wondering what's meant by dynamic break is not
working? I understand how it could lead to better compilation, but a mere
'not working' at the very least intrigues me :)

I have actually used this construct, though its purpose is mainly in parser
routines, so I guess I could always goto instead.
On Nov 19, 2010 12:21 AM, "Patrick ALLAERT" <patrick.allaert@gmail.com>
wrote:
> 2010/11/18 Derick Rethans <derick@php.net>:
> > […]
>
> Not sure, but at least, it is in *your* release notes :-)
> http://www.php.net/~derick/meeting-notes.html#break-var

---

## #50389 — Tjerk Meesters — 2010-11-19T14:57:48+00:00

URL: https://externals.io/message/50348#50389 · In reply to: #50357

Reading those notes I'm wondering what's meant by dynamic break is not
working? I understand how it could lead to better compilation, but a mere
'not working' at the very least intrigues me :)

I have actually used this construct, though its purpose is mainly in parser
routines, so I guess I could always goto instead.
On Nov 19, 2010 12:21 AM, "Patrick ALLAERT" <patrick.allaert@gmail.com>
wrote:
> 2010/11/18 Derick Rethans <derick@php.net>:
> > […]
>
> Not sure, but at least, it is in *your* release notes :-)
> http://www.php.net/~derick/meeting-notes.html#break-var

---

## #50399 — Ilia Alshanetsky — 2010-11-20T02:10:41+00:00

URL: https://externals.io/message/50348#50399 · In reply to: #50384

+1 to removing it. I think now that we have goto, this functionality
does not make much sense.


> without $var it would be possible to compile break/continue into
> ZEND_FREE/ZEND_SWITCH_FREE and ZEND_JMP.
>
> I also thought it would allow to remove op_array->brk_cont_array completely,
> but it's also used for exception handling. :(
>
> Thanks. Dmitry.
>
>
>
> Derick Rethans wrote:
> > […]

---

## #50406 — Felipe Pena — 2010-11-22T00:24:16+00:00

URL: https://externals.io/message/50348#50406 · In reply to: #50348

2010/11/18 Dmitry Stogov <dmitry@zend.com>

> Hi,


> Previously we decided to remove "break/continue $var" syntax.
> I even implemented it in PHP6 brunch, however it wasn't backported into
>  trunk. Could I do it?
>
>
+1 to removing it.

-- 
Regards,
Felipe Pena

---

## #50407 — Stas Malyshev — 2010-11-22T01:15:29+00:00

URL: https://externals.io/message/50348#50407 · In reply to: #50406

Hi!

> > […]

I think it's fine to remove it.

-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #50467 — Dmitry Stogov — 2010-11-24T12:11:36+00:00

URL: https://externals.io/message/50348#50467 · In reply to: #50348

the proposed patch (backport from php6) is attached.
I think this feature is completely useless and it was agreed to remove 
it about 5 years ago.

Derick, can I commit the patch today?

Thanks. Dmitry.

Dmitry Stogov wrote:
> Hi,
> 
> Previously we decided to remove "break/continue $var" syntax.
> I even implemented it in PHP6 brunch, however it wasn't backported into 
>  trunk. Could I do it?
> 
> Thanks. Dmitry.

---

## #50468 — Derick Rethans — 2010-11-24T12:17:30+00:00

URL: https://externals.io/message/50348#50468 · In reply to: #50467

> the proposed patch (backport from php6) is attached.
> I think this feature is completely useless and it was agreed to remove it
> about 5 years ago.
> 
> Derick, can I commit the patch today?

Sure. You know this stuff best :-)

cheers,
Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug

---

## #50471 — Pierre Joye — 2010-11-24T14:11:19+00:00

URL: https://externals.io/message/50348#50471 · In reply to: #50467

Hi Dmitry,

From a BC point of view, the impact will be minimal. The only project
I found relying on this syntax is XPath  class [1].


Please add a note the upgrade guide as well in trunk, maybe in a BC
break sections.

[1] http://google.com/codesearch?hl=en&sa=N&q=lang:php+break\s{1,}%28\%24\w%29

Cheers,


> the proposed patch (backport from php6) is attached.
> I think this feature is completely useless and it was agreed to remove it
> about 5 years ago.
>
> Derick, can I commit the patch today?
>
> Thanks. Dmitry.
>
> Dmitry Stogov wrote:
> > […]
>
> Index: Zend/zend_execute.c
> ===================================================================
> --- Zend/zend_execute.c (revision 305710)
> +++ Zend/zend_execute.c (working copy)
> @@ -1362,21 +1362,12 @@
>        }
>  }
>
> -static inline zend_brk_cont_element* zend_brk_cont(zval *nest_levels_zval,
> int array_offset, const zend_op_array *op_array, const temp_variable *Ts
> TSRMLS_DC)
> +static inline zend_brk_cont_element* zend_brk_cont(int nest_levels, int
> array_offset, const zend_op_array *op_array, const temp_variable *Ts
> TSRMLS_DC)
>  {
>        zval tmp;
> -       int nest_levels, original_nest_levels;
> +       int original_nest_levels = nest_levels;
>        zend_brk_cont_element *jmp_to;
>
> -       if (nest_levels_zval->type != IS_LONG) {
> -               tmp = *nest_levels_zval;
> -               zval_copy_ctor(&tmp);
> -               convert_to_long(&tmp);
> -               nest_levels = tmp.value.lval;
> -       } else {
> -               nest_levels = nest_levels_zval->value.lval;
> -       }
> -       original_nest_levels = nest_levels;
>        do {
>                if (array_offset==-1) {
>                        zend_error_noreturn(E_ERROR, "Cannot break/continue
> %d level%s", original_nest_levels, (original_nest_levels == 1) ? "" : "s");
> Index: Zend/zend_vm_execute.h
> ===================================================================
> --- Zend/zend_vm_execute.h      (revision 305710)
> +++ Zend/zend_vm_execute.h      (working copy)
> @@ -1304,11 +1304,10 @@
>  static int ZEND_FASTCALL
>  ZEND_BRK_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
>  {
>        USE_OPLINE
> -
>        zend_brk_cont_element *el;
>
>        SAVE_OPLINE();
> -       el = zend_brk_cont(opline->op2.zv, opline->op1.opline_num,
> +       el = zend_brk_cont(Z_LVAL_P(opline->op2.zv), opline->op1.opline_num,
>                           EX(op_array), EX_Ts() TSRMLS_CC);
>
>        ZEND_VM_JMP(EX(op_array)->opcodes + el->brk);
> @@ -1317,11 +1316,10 @@
>  static int ZEND_FASTCALL
>  ZEND_CONT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
>  {
>        USE_OPLINE
> -
>        zend_brk_cont_element *el;
>
>        SAVE_OPLINE();
> -       el = zend_brk_cont(opline->op2.zv, opline->op1.opline_num,
> +       el = zend_brk_cont(Z_LVAL_P(opline->op2.zv), opline->op1.opline_num,
>                           EX(op_array), EX_Ts() TSRMLS_CC);
>
>        ZEND_VM_JMP(EX(op_array)->opcodes + el->cont);
> @@ -1334,7 +1332,7 @@
>        zend_brk_cont_element *el;
>
>        SAVE_OPLINE();
> -       el = zend_brk_cont(opline->op2.zv, opline->extended_value,
> +       el = zend_brk_cont(Z_LVAL_P(opline->op2.zv), opline->extended_value,
>                           EX(op_array), EX_Ts() TSRMLS_CC);
>
>        brk_opline = EX(op_array)->opcodes + el->brk;
> @@ -1477,32 +1475,6 @@
>  }
>
>
> -static int ZEND_FASTCALL
>  ZEND_BRK_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
> -{
> -       USE_OPLINE
> -       zend_free_op free_op2;
> -       zend_brk_cont_element *el;
> -
> -       SAVE_OPLINE();
> -       el = zend_brk_cont(_get_zval_ptr_tmp(opline->op2.var, EX_Ts(),
> &free_op2 TSRMLS_CC), opline->op1.opline_num,
> -                          EX(op_array), EX_Ts() TSRMLS_CC);
> -       zval_dtor(free_op2.var);
> -       ZEND_VM_JMP(EX(op_array)->opcodes + el->brk);
> -}
> -
> -static int ZEND_FASTCALL
>  ZEND_CONT_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
> -{
> -       USE_OPLINE
> -       zend_free_op free_op2;
> -       zend_brk_cont_element *el;
> -
> -       SAVE_OPLINE();
> -       el = zend_brk_cont(_get_zval_ptr_tmp(opline->op2.var, EX_Ts(),
> &free_op2 TSRMLS_CC), opline->op1.opline_num,
> -                          EX(op_array), EX_Ts() TSRMLS_CC);
> -       zval_dtor(free_op2.var);
> -       ZEND_VM_JMP(EX(op_array)->opcodes + el->cont);
> -}
> -
>  static int ZEND_FASTCALL
>  ZEND_FETCH_CLASS_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
>  {
>        USE_OPLINE
> @@ -1599,32 +1571,6 @@
>  }
>
>
> -static int ZEND_FASTCALL
>  ZEND_BRK_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
> -{
> -       USE_OPLINE
> -       zend_free_op free_op2;
> -       zend_brk_cont_element *el;
> -
> -       SAVE_OPLINE();
> -       el = zend_brk_cont(_get_zval_ptr_var(opline->op2.var, EX_Ts(),
> &free_op2 TSRMLS_CC), opline->op1.opline_num,
> -                          EX(op_array), EX_Ts() TSRMLS_CC);
> -       if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
> -       ZEND_VM_JMP(EX(op_array)->opcodes + el->brk);
> -}
> -
> -static int ZEND_FASTCALL
>  ZEND_CONT_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
> -{
> -       USE_OPLINE
> -       zend_free_op free_op2;
> -       zend_brk_cont_element *el;
> -
> -       SAVE_OPLINE();
> -       el = zend_brk_cont(_get_zval_ptr_var(opline->op2.var, EX_Ts(),
> &free_op2 TSRMLS_CC), opline->op1.opline_num,
> -                          EX(op_array), EX_Ts() TSRMLS_CC);
> -       if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
> -       ZEND_VM_JMP(EX(op_array)->opcodes + el->cont);
> -}
> -
>  static int ZEND_FASTCALL
>  ZEND_FETCH_CLASS_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
>  {
>        USE_OPLINE
> @@ -1754,32 +1700,6 @@
>  }
>
>
> -static int ZEND_FASTCALL
>  ZEND_BRK_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
> -{
> -       USE_OPLINE
> -
> -       zend_brk_cont_element *el;
> -
> -       SAVE_OPLINE();
> -       el = zend_brk_cont(_get_zval_ptr_cv_BP_VAR_R(EX_CVs(),
> opline->op2.var TSRMLS_CC), opline->op1.opline_num,
> -                          EX(op_array), EX_Ts() TSRMLS_CC);
> -
> -       ZEND_VM_JMP(EX(op_array)->opcodes + el->brk);
> -}
> -
> -static int ZEND_FASTCALL
>  ZEND_CONT_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
> -{
> -       USE_OPLINE
> -
> -       zend_brk_cont_element *el;
> -
> -       SAVE_OPLINE();
> -       el = zend_brk_cont(_get_zval_ptr_cv_BP_VAR_R(EX_CVs(),
> opline->op2.var TSRMLS_CC), opline->op1.opline_num,
> -                          EX(op_array), EX_Ts() TSRMLS_CC);
> -
> -       ZEND_VM_JMP(EX(op_array)->opcodes + el->cont);
> -}
> -
>  static int ZEND_FASTCALL
>  ZEND_BW_NOT_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
>  {
>        USE_OPLINE
> @@ -36791,55 +36711,55 @@
>        ZEND_NULL_HANDLER,
>        ZEND_NULL_HANDLER,
>        ZEND_BRK_SPEC_CONST_HANDLER,
> -       ZEND_BRK_SPEC_TMP_HANDLER,
> -       ZEND_BRK_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_BRK_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_BRK_SPEC_CONST_HANDLER,
> -       ZEND_BRK_SPEC_TMP_HANDLER,
> -       ZEND_BRK_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_BRK_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_BRK_SPEC_CONST_HANDLER,
> -       ZEND_BRK_SPEC_TMP_HANDLER,
> -       ZEND_BRK_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_BRK_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_BRK_SPEC_CONST_HANDLER,
> -       ZEND_BRK_SPEC_TMP_HANDLER,
> -       ZEND_BRK_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_BRK_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_BRK_SPEC_CONST_HANDLER,
> -       ZEND_BRK_SPEC_TMP_HANDLER,
> -       ZEND_BRK_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_BRK_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_CONT_SPEC_CONST_HANDLER,
> -       ZEND_CONT_SPEC_TMP_HANDLER,
> -       ZEND_CONT_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_CONT_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_CONT_SPEC_CONST_HANDLER,
> -       ZEND_CONT_SPEC_TMP_HANDLER,
> -       ZEND_CONT_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_CONT_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_CONT_SPEC_CONST_HANDLER,
> -       ZEND_CONT_SPEC_TMP_HANDLER,
> -       ZEND_CONT_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_CONT_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_CONT_SPEC_CONST_HANDLER,
> -       ZEND_CONT_SPEC_TMP_HANDLER,
> -       ZEND_CONT_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_CONT_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_CONT_SPEC_CONST_HANDLER,
> -       ZEND_CONT_SPEC_TMP_HANDLER,
> -       ZEND_CONT_SPEC_VAR_HANDLER,
>        ZEND_NULL_HANDLER,
> -       ZEND_CONT_SPEC_CV_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
> +       ZEND_NULL_HANDLER,
>        ZEND_BOOL_SPEC_CONST_HANDLER,
>        ZEND_BOOL_SPEC_CONST_HANDLER,
>        ZEND_BOOL_SPEC_CONST_HANDLER,
> Index: Zend/zend_compile.c
> ===================================================================
> --- Zend/zend_compile.c (revision 305711)
> +++ Zend/zend_compile.c (working copy)
> @@ -4302,6 +4302,11 @@
>        opline->op1.opline_num = CG(context).current_brk_cont;
>        SET_UNUSED(opline->op1);
>        if (expr) {
> +               if (expr->op_type != IS_CONST) {
> +                       zend_error(E_COMPILE_ERROR, "'%s' operator with
> non-constant operand is no longer supported", op == ZEND_BRK ? "break" :
> "continue");
> +               } else if (Z_TYPE(expr->u.constant) != IS_LONG ||
> Z_LVAL(expr->u.constant) < 1) {
> +                       zend_error(E_COMPILE_ERROR, "'%s' operator accepts
> only positive numbers", op == ZEND_BRK ? "break" : "continue");
> +               }
>                SET_NODE(opline->op2, expr);
>        } else {
>                LITERAL_LONG(opline->op2, 1);
> Index: Zend/zend_vm_def.h
> ===================================================================
> --- Zend/zend_vm_def.h  (revision 305710)
> +++ Zend/zend_vm_def.h  (working copy)
> @@ -3171,27 +3171,25 @@
>        ZEND_VM_NEXT_OPCODE();
>  }
>
> -ZEND_VM_HANDLER(50, ZEND_BRK, ANY, CONST|TMP|VAR|CV)
> +ZEND_VM_HANDLER(50, ZEND_BRK, ANY, CONST)
>  {
>        USE_OPLINE
> -       zend_free_op free_op2;
>        zend_brk_cont_element *el;
>
>        SAVE_OPLINE();
> -       el = zend_brk_cont(GET_OP2_ZVAL_PTR(BP_VAR_R),
> opline->op1.opline_num,
> +       el = zend_brk_cont(Z_LVAL_P(opline->op2.zv), opline->op1.opline_num,
>                           EX(op_array), EX_Ts() TSRMLS_CC);
>        FREE_OP2();
>        ZEND_VM_JMP(EX(op_array)->opcodes + el->brk);
>  }
>
> -ZEND_VM_HANDLER(51, ZEND_CONT, ANY, CONST|TMP|VAR|CV)
> +ZEND_VM_HANDLER(51, ZEND_CONT, ANY, CONST)
>  {
>        USE_OPLINE
> -       zend_free_op free_op2;
>        zend_brk_cont_element *el;
>
>        SAVE_OPLINE();
> -       el = zend_brk_cont(GET_OP2_ZVAL_PTR(BP_VAR_R),
> opline->op1.opline_num,
> +       el = zend_brk_cont(Z_LVAL_P(opline->op2.zv), opline->op1.opline_num,
>                           EX(op_array), EX_Ts() TSRMLS_CC);
>        FREE_OP2();
>        ZEND_VM_JMP(EX(op_array)->opcodes + el->cont);
> @@ -3204,7 +3202,7 @@
>        zend_brk_cont_element *el;
>
>        SAVE_OPLINE();
> -       el = zend_brk_cont(opline->op2.zv, opline->extended_value,
> +       el = zend_brk_cont(Z_LVAL_P(opline->op2.zv), opline->extended_value,
>                           EX(op_array), EX_Ts() TSRMLS_CC);
>
>        brk_opline = EX(op_array)->opcodes + el->brk;
>
>
> --
> 
> 
>



-- 
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org

---

## #50473 — Dmitry Stogov — 2010-11-24T16:38:43+00:00

URL: https://externals.io/message/50348#50473 · In reply to: #50471

Pierre Joye wrote:
> Hi Dmitry,
> 
> From a BC point of view, the impact will be minimal. The only project
> I found relying on this syntax is XPath  class [1].

I'm wondered why they use it, because their var ($parseBlock) is always 1.

> 
> Please add a note the upgrade guide as well in trunk, maybe in a BC
> break sections.

done.

Thanks. Dmitry.

> [1] http://google.com/codesearch?hl=en&sa=N&q=lang:php+break\s{1,}%28\%24\w%29
> 
> Cheers,
> 
> 
> > […]
> 
> 
> 
> --
> Pierre
> 
> @pierrejoye | http://blog.thepimp.net | http://www.libgd.org
