doy57007 2015-01-19 15:53
浏览 35
已采纳

解析错误:语法错误,意外'}'在Wordpress插件激活php 5.5中

I'm getting this error when trying to activate a custom plugin on my localhost, I have a working copy of the website working that runs php 5.2, where this problem does not occur.

localhost: PHP Version 5.5.14

this is the offending snippet, at the last line:

...
// Widget Backend
public function form( $instance ) {
    if ( isset( $instance[ 'title' ] ) ) {
        $title = $instance[ 'title' ];
    } else {
        $title = __( 'Delivery', 'delivery_widget_domain' );
    }

    if (isset($instance['sub_title'])){
        $sub_title = $instance['sub_title'];
    } else {
        $sub_title = __('escolha uma categoria', 'delivery_widget_domain');
    }
    // Widget admin form
    ?>
    <p>
        <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
    </p>
    <p>
        <label for="<?php echo $this->get_field_id('sub_title'); ?>"><?php _e('Sub Título:'); ?></label>
        <input class="widefat" id="<?php echo $this->get_field_id('sub_title');?>" name="<?php echo $this->get_field_name('sub_title'); ?>" type="text" value="<?php echo esc_attr($sub_title); ?>" />
    </p>
  <?php
} // <----- this line
...

Why this is happening?

EDIT: paste bin of the file, the error is on line 55 http://pastebin.com/hHxnfsDA

error message ( ! ) Parse error: parse error in /.../widgets/delivery.php on line 55
Call Stack
#   Time    Memory  Function    Location
1   0.0013  391472  {main}( )   ../plugins.php:0
2   0.8336  47175152    plugin_sandbox_scrape( )    ../plugins.php:153
3   0.8337  47177328    include( '/.../plugins/portalsabores-plugin/portalsabores-plugin.php' ) ../plugins.php:151

and on cli:

Parse error: syntax error, unexpected '}' in Sites/portalsabores/wp-content/plugins/portalsabores-plugin/widgets/delivery.php on line 55
  • 写回答

2条回答 默认 最新

  • dongyuelian9602 2015-01-19 17:18
    关注

    The first PHP tag (line 1 of the Pastebin file) needs to be <?php (and not <?) if you want to open <?php in the rest of the file.

    Look at this test script :

    <?
    if (true)
    {
        ?>
        <?
    }
    
    if (true)
    {
        ?>
        <?php
    }
    ?>
    

    Online evaluation of this test script: http://3v4l.org/tg8SU

    PHP works as expected when you open PHP code with <? line 5, but it will detect a parse error at line 12.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装