致命错误:“中断"不在上下文中的“循环"或“切换"上下文中 [英] Fatal error: 'break' not in the 'loop' or 'switch' context in
问题描述
我已经建立了一个wordpress博客(我导入了数据库),并且抛出了这个错误
致命错误:中断"不在循环"或切换"上下文中 /home/kbuzz/webapps/kb_blog/wp-content/plugins/types/embedded/common/toolset-forms/lib/adodb-time.inc.php 在第1012行
下面的代码是从1004
行到1013
function adodb_tz_offset($gmt,$isphp5)
{
$zhrs = abs($gmt)/3600;
$hrs = floor($zhrs);
if ($isphp5)
return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
else
return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
break;
}
PHP 5.xx ,for
,foreach
,while
或
PHP 7.0及更高版本,在for
,foreach
,while
或switch
语句之外,不再允许使用break
语句,并且会出现致命错误.>
示例代码:
<?php
if (2 == 1 + 1) {
echo "Dummy Example of break inside if condition";
break; // - Valid in php 5.*
// - Gives a Fatal error in PHP 7.*.*:
// "Fatal error: 'break' not in the 'loop' or 'switch' context in ... "
}
?>
I've setup a wordpress blog (I imported the db) and it's throwing this error
Fatal error: 'break' not in the 'loop' or 'switch' context in /home/kbuzz/webapps/kb_blog/wp-content/plugins/types/embedded/common/toolset-forms/lib/adodb-time.inc.php on line 1012
The code is below from line 1004
to 1013
function adodb_tz_offset($gmt,$isphp5)
{
$zhrs = abs($gmt)/3600;
$hrs = floor($zhrs);
if ($isphp5)
return sprintf('%s%02d%02d',($gmt<=0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
else
return sprintf('%s%02d%02d',($gmt<0)?'+':'-',floor($zhrs),($zhrs-$hrs)*60);
break;
}
PHP 5.x.x, a break
statement outside a for
, foreach
, while
or switch
statement DID NOT throw an error message and was syntactically okay.
PHP 7.0 and higher, a break
statement is no longer permitted outside a for
, foreach
, while
or switch
statement and gives a fatal error.
Example code:
<?php
if (2 == 1 + 1) {
echo "Dummy Example of break inside if condition";
break; // - Valid in php 5.*
// - Gives a Fatal error in PHP 7.*.*:
// "Fatal error: 'break' not in the 'loop' or 'switch' context in ... "
}
?>
这篇关于致命错误:“中断"不在上下文中的“循环"或“切换"上下文中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!