doujing5846 2017-05-16 11:44
浏览 84
已采纳

致命错误:Switch语句只能包含一个默认子句(php7)

I use php ver. 7.1.0 and now I have problem

Fatal error: Switch statements may only contain one default clause in /icore.php on line 477

Here's the code:

476  case 'html':
477  default:
478  echo $std;
479
480  if ( $desc != '' )
481    echo '<br /><span class="description">' . $desc . '</span>';
482
483  break;

Can I fix it?

Full code for switch:

switch ( $type ) {

                case 'heading':
                    echo '</td></tr><tr valign="top"><td colspan="2"><h4>' . $desc . '</h4>';
                    break;

                case 'checkbox':
                    echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';

                    break;

                case 'select':
                    echo '<select class="select' . $field_class . '" name="' . $shortname_options . '[' . $id . ']' . '">';

                    foreach ( $choices as $value => $label )
                        echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';

                    echo '</select>';

                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';

                    break;

                case 'radio':
                    $i = 0;
                    foreach ( $choices as $value => $label ) {
                        echo '<input class="radio' . $field_class . '" type="radio" name="' . $shortname_options . '[' . $id . ']' . '" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
                        if ( $i < count( $options ) - 1 )
                            echo '<br />';
                        $i++;
                    }

                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';

                    break;

                case 'textarea':
                    echo '<textarea class="' . $field_class . '" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" rows="5" cols="30">' . wp_htmledit_pre( $options[$id] ) . '</textarea>';

                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';

                    break;

                case 'password':
                    echo '<input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" />';

                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';

                    break;

                case 'text':
                default:
                    echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';

                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';

                    break;

                case 'html':
                default:
                    echo $std;

                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';

                    break;

                case 'upload':
                default:
                   echo '<input id="' . $id . '" class="upload-url' . $field_class . '" type="text" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" /><input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload" />';

                if ( $desc != '' )
                   echo '
                   <span class="description">' . $desc . '</span>';
                echo '<div class="upload-img-preview">';
                if (esc_attr( $options[$id] <> '')) {
                    echo '<img class="upload-img-preview" src='.esc_attr( $options[$id]).' />';
                    echo '<a class="removeupload">'. __('Delete Image', 'icore') .'</a>';
                }
                    echo '</div>';
                    break;

                    case 'slide':
                        if ( $desc != '' )
                            echo '<span class="description' . $field_class . '">' . $desc . '</span>';

                        echo '<br /><span id="slides-details-button"></span>';
                        echo '<ul id="slideshow_list">';

                        if ( $options['slider'] <> '' ) {

                            $slides = array();
                            foreach ($options[$id]['title'] as $k => $v) {
                                $slides[] = array(
                                    'title' => $v,
                                    'link' => $options[$id]['link'][$k],
                                    'caption' => $options[$id]['caption'][$k],
                                    'image' => $options[$id]['image'][$k]
                                );
                            }

                            $i = 1;
                            foreach ($slides as $slide) {
                                echo '<li class="slide">';
                                echo '<a class="editslideimage">edit</a>';
                                echo '<div class="image-details slidedetails">';
                                echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
                                echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="'.$slide['title'].'" type="text" />';

                                echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
                                echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="'.$slide['link'].'" type="text" />';

                                echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
                                echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4">'.$slide['caption'].'</textarea>';

                                echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
                                echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="'.$slide['image'].'" type="text" />
                                <a href="'.get_option('siteurl').'/wp-admin/admin-ajax.php?action=choice&width=150&height=100" id="'.$id.'_button" class="button upbutton">' . __( 'Upload','InterStellar' ) . '</a>';
                                echo '<a class="doneslideimage">Done</a>';
                                echo '</div>';
                                echo '<div class="clear"></div><div class="upload-img-preview">';
                                if ( $slide['image'] != "" )
                                {
                                    echo '<img class="upload-img-preview" id="image_'. $id .'_image_'.$i.'" src="'.$slide['image'].'" />';
                                }
                                echo '</div>';
                                echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide', 'InterStellar' ) . '</a>';
                                echo '</li>';
                                $i++;
                            }

                        } else {
                            $i = 1;
                            echo '<li class="slide">';
                            echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
                            echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="" type="text" />';

                            echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
                            echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="" type="text" />';

                            echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
                            echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4"></textarea>';

                            echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
                            echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="" type="text" />
                            <a href="'.get_option('siteurl').'/wp-admin/admin-ajax.php?action=choice&width=150&height=100" id="'.$id.'_button" class="button upbutton">' . __( 'Upload', 'icore' ) . '</a>';

                            echo '<div class="clear"></div><div class="upload-img-preview">';
                            echo '</div>';
                            echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide','InterStellar' ) . '</a>';
                            echo '</li>';
                        }

                        echo '</ul>';
                        break;

            }
        }

Is this enought?

  • 写回答

1条回答 默认 最新

  • drg17404 2017-05-16 11:56
    关注

    You can not use a case statement inside a case. Try this corrected code

    switch ( $type ) {
    
                case 'heading':
                    echo '</td></tr><tr valign="top"><td colspan="2"><h4>' . $desc . '</h4>';
                    break;
    
                case 'checkbox':
                    echo '<input class="checkbox' . $field_class . '" type="checkbox" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="1" ' . checked( $options[$id], 1, false ) . ' /> <label for="' . $id . '">' . $desc . '</label>';
    
                    break;
    
                case 'select':
                    echo '<select class="select' . $field_class . '" name="' . $shortname_options . '[' . $id . ']' . '">';
    
                    foreach ( $choices as $value => $label )
                        echo '<option value="' . esc_attr( $value ) . '"' . selected( $options[$id], $value, false ) . '>' . $label . '</option>';
    
                    echo '</select>';
    
                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';
    
                    break;
    
                case 'radio':
                    $i = 0;
                    foreach ( $choices as $value => $label ) {
                        echo '<input class="radio' . $field_class . '" type="radio" name="' . $shortname_options . '[' . $id . ']' . '" id="' . $id . $i . '" value="' . esc_attr( $value ) . '" ' . checked( $options[$id], $value, false ) . '> <label for="' . $id . $i . '">' . $label . '</label>';
                        if ( $i < count( $options ) - 1 )
                            echo '<br />';
                        $i++;
                    }
    
                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';
    
                    break;
    
                case 'textarea':
                    echo '<textarea class="' . $field_class . '" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" rows="5" cols="30">' . wp_htmledit_pre( $options[$id] ) . '</textarea>';
    
                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';
    
                    break;
    
                case 'password':
                    echo '<input class="regular-text' . $field_class . '" type="password" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" />';
    
                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';
    
                    break;
    
                case 'text':
                    echo '<input class="regular-text' . $field_class . '" type="text" id="' . $id . '" name="' . $shortname_options . '[' . $id . ']' . '" placeholder="' . $std . '" value="' . esc_attr( $options[$id] ) . '" />';
    
                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';
    
                    break;
    
                case 'html':
                    echo $std;
    
                    if ( $desc != '' )
                        echo '<br /><span class="description">' . $desc . '</span>';
    
                    break;
    
                default:
                   echo '<input id="' . $id . '" class="upload-url' . $field_class . '" type="text" name="' . $shortname_options . '[' . $id . ']' . '" value="' . esc_attr( $options[$id] ) . '" /><input id="st_upload_button" class="st_upload_button" type="button" name="upload_button" value="Upload" />';
    
                if ( $desc != '' )
                   echo '
                   <span class="description">' . $desc . '</span>';
                echo '<div class="upload-img-preview">';
                if (esc_attr( $options[$id] <> '')) {
                    echo '<img class="upload-img-preview" src='.esc_attr( $options[$id]).' />';
                    echo '<a class="removeupload">'. __('Delete Image', 'icore') .'</a>';
                }
                    echo '</div>';
                    break;
    
                    case 'slide':
                        if ( $desc != '' )
                            echo '<span class="description' . $field_class . '">' . $desc . '</span>';
    
                        echo '<br /><span id="slides-details-button"></span>';
                        echo '<ul id="slideshow_list">';
    
                        if ( $options['slider'] <> '' ) {
    
                            $slides = array();
                            foreach ($options[$id]['title'] as $k => $v) {
                                $slides[] = array(
                                    'title' => $v,
                                    'link' => $options[$id]['link'][$k],
                                    'caption' => $options[$id]['caption'][$k],
                                    'image' => $options[$id]['image'][$k]
                                );
                            }
    
                            $i = 1;
                            foreach ($slides as $slide) {
                                echo '<li class="slide">';
                                echo '<a class="editslideimage">edit</a>';
                                echo '<div class="image-details slidedetails">';
                                echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
                                echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="'.$slide['title'].'" type="text" />';
    
                                echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
                                echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="'.$slide['link'].'" type="text" />';
    
                                echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
                                echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4">'.$slide['caption'].'</textarea>';
    
                                echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
                                echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="'.$slide['image'].'" type="text" />
                                <a href="'.get_option('siteurl').'/wp-admin/admin-ajax.php?action=choice&width=150&height=100" id="'.$id.'_button" class="button upbutton">' . __( 'Upload','InterStellar' ) . '</a>';
                                echo '<a class="doneslideimage">Done</a>';
                                echo '</div>';
                                echo '<div class="clear"></div><div class="upload-img-preview">';
                                if ( $slide['image'] != "" )
                                {
                                    echo '<img class="upload-img-preview" id="image_'. $id .'_image_'.$i.'" src="'.$slide['image'].'" />';
                                }
                                echo '</div>';
                                echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide', 'InterStellar' ) . '</a>';
                                echo '</li>';
                                $i++;
                            }
    
                        } else {
                            $i = 1;
                            echo '<li class="slide">';
                            echo '<span class="description">' . __( 'Slide Title', 'icore' ) . '</span>';
                            echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][title][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="" type="text" />';
    
                            echo '<span class="description">' . __( 'Slide Link', 'icore' ) . '</span>';
                            echo '<input class="regular-text' . $field_class . '" name="' . $shortname_options . '[' . $id . '][link][]" placeholder="' . $std . '" id="'. $id .'_title_'.$i.'"  value="" type="text" />';
    
                            echo '<span class="description">' . __( 'Slide Caption', 'icore' ) . '</span>';
                            echo '<textarea class="'.$field_class.'" name="' . $shortname_options . '[' . $id . '][caption][]" id="'. $id .'_caption_'.$i.'" cols="40" rows="4"></textarea>';
    
                            echo '<span class="description">' . __( 'Slide Image', 'icore' ) . '</span>';
                            echo '<input class="upload-input-text src" name="' . $shortname_options . '[' . $id . '][image][]" id="'. $id .'_image_'.$i.'" type="text" value="" type="text" />
                            <a href="'.get_option('siteurl').'/wp-admin/admin-ajax.php?action=choice&width=150&height=100" id="'.$id.'_button" class="button upbutton">' . __( 'Upload', 'icore' ) . '</a>';
    
                            echo '<div class="clear"></div><div class="upload-img-preview">';
                            echo '</div>';
                            echo '<a class="remove_slide submitdelete">' . __( 'Delete Slide','InterStellar' ) . '</a>';
                            echo '</li>';
                        }
    
                        echo '</ul>';
                        break;
    
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上