php 致命错误:“中断”不在“循环”或“切换”上下文中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34871198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: 'break' not in the 'loop' or 'switch' context in
提问by Samuel Muiruri
I've setup a wordpress blog (I imported the db) and it's throwing this error
我已经设置了一个 wordpress 博客(我导入了数据库)并且它抛出了这个错误
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
致命错误:“中断”不在 /home/kbuzz/webapps/kb_blog/wp-content/plugins/types/embedded/common/toolset-forms/lib/adodb-time.inc 中的“循环”或“切换”上下文中.php 在线 1012
The code is below from line 1004
to 1013
代码在下面从行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;
}
回答by Basil Musa
PHP 5.x.x, a break
statement outside a for
, foreach
, while
or switch
statement DID NOTthrow an error message and was syntactically okay.
PHP 5.xx, , , orbreak
语句之外的语句没有抛出错误消息并且在语法上没有问题。for
foreach
while
switch
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.
PHP 7.0 及更高版本,break
不再允许在for
, foreach
, while
orswitch
语句之外使用语句并给出致命错误。
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 ... "
}
?>
回答by David Kaushik
look at the break;
看着那(这 break;
replace with
用。。。来代替
return false;
return false;
in your code and it will work.
在您的代码中,它将起作用。
回答by Samuel Muiruri
Removing break
fixed it
删除break
固定它
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);
}