我有时会在以下位置收到此错误:
if( true == $objWebsite ) {
$arrobjProperties = (array) $objWebsite->fetchProperties( );
if( false == array_key_exists( $Id, $Properties ) ) {
break;
}
$strBaseName = $strPortalSuffix . '/';
return $strBaseName;
}
$strBaseName = $strSuffix ;
return $strBaseName;
我已尝试重现此问题。但没有取得任何进展。 $Id, $Properties 具有收到的值(value)。
有谁知道“不能中断/继续 1 级”何时出现在 PHP 中?
我看过这篇文章PHP Fatal error: Cannot break/continue .但没有得到任何帮助。
最佳答案
您不能“中断”if 语句。您只能从循环中中断。
如果你想用它来打破调用函数中的循环,你需要通过返回值来处理它——或者抛出异常。
返回值方法:
while (MyLoop) {
$strSecureBaseName = mySubFunction();
if ($strSecureBaseName === false) { // Note the triple equals sign.
break;
}
// Use $strSecureBaseName;
}
// Function mySubFunction() returns the name, or false if not found.
使用异常——这里是一个很好的例子:http://php.net/manual/en/language.exceptions.php
<?php
function inverse($x) {
if (!$x) {
throw new \Exception('Division by zero.');
} else {
return 1/$x;
}
}
try {
echo inverse(5) . "\n";
echo inverse(0) . "\n";
} catch (\Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
// Continue execution
echo 'Hello World';
?>
关于php - 为什么 'Cannot break/continue 1 level' 出现在 PHP 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11988281/