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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:15:28  来源:igfitidea点击:

Fatal error: 'break' not in the 'loop' or 'switch' context in

phpwordpress

提问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 1004to 1013

代码在下面从行10041013

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 breakstatement outside a for, foreach, whileor switchstatement DID NOTthrow an error message and was syntactically okay.

PHP 5.xx, , , orbreak语句之外的语句没有抛出错误消息并且在语法上没有问题。forforeachwhileswitch

PHP 7.0 and higher, a breakstatement is no longer permitted outside a for, foreach, whileor switchstatement and gives a fatal error.

PHP 7.0 及更高版本break不再允许在for, foreach, whileorswitch语句之外使用语句并给出致命错误。

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 breakfixed 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); 
}