Skip to content
Advertisement

Why does ‘Cannot break/continue 1 level’ comes in PHP?

I am getting sometimes this error on production at:

JavaScript

I have tried to reproduce this issue. But not getting any progress. $Id, $Properties having value received.

Does anyone know when does ‘Cannot break/continue 1 level’ comes in PHP?

I have seen this post PHP Fatal error: Cannot break/continue. But didn’t got any help.

Advertisement

Answer

You can’t “break” from an if statement. You can only break from a loop.

If you want to use it to break from a loop in a calling function, you need to handle this by return value – or throw an exception.


Return value method:

JavaScript

Using exceptions – beautiful example here: http://php.net/manual/en/language.exceptions.php

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement