致命错误:“中断"不在上下文中的“循环"或“切换"上下文中 [英] Fatal error: 'break' not in the 'loop' or 'switch' context in

查看:169
本文介绍了致命错误:“中断"不在上下文中的“循环"或“切换"上下文中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个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 forforeachwhilebreak语句>语句 DID NOT 会引发错误消息,并且在语法上还可以.

PHP 7.0及更高版本,在forforeachwhileswitch语句之外,不再允许使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆