It worked on localhost, and when transferring to hosting, I started to generate an error:

Parse error: syntax error, unexpected '}' in /home/taradajk/bti-zp.com.ua/www/wp-content/themes/bti/phones.php on line 46

I cite this piece of code:

function widget($args, $instance) { extract( $args ); $phone1 = $instance['phone1']; $phone2 = $instance['phone2']; $phone3 = $instance['phone3']; $office = $instance['office']; $email = $instance['email']; echo $before_widget; ?> <h3><i class="fa fa-phone" aria-hidden="true"></i> Звоните</h3> <ul class="phones"> <?php if($phone1): ?><li><?php echo $phone1; ?></li><? endif ?> <?php if($phone2): ?><li><?php echo $phone2; ?></li><? endif ?> <?php if($phone3): ?><li><?php echo $phone3; ?></li><? endif ?> </ul> <a data-remodal-target="callme" class="recallme"><i class="fa fa-question-circle" aria-hidden="true"></i> Задать вопрос</a> <?php if($email): ?><h3><i class="fa fa-envelope-o" aria-hidden="true"></i> Пишите</h3> <p><?php echo $email; ?></p><? endif ?> <?php if($office): ?><h3><i class="fa fa-home" aria-hidden="true"></i> Приходите</h3> <p><?php echo $office; ?></p><? endif ?> <div class="remodal" data-remodal-id="callme"> <button data-remodal-action="close" class="remodal-close"></button> <h1>Хотите задать вопрос?</h1> <p>Укажите свое имя и мобильный телефон, а мы перезвоним!</p> <?php echo do_shortcode('[contact-form-7 id="60" title="Задать вопрос"]'); ?> </div> <?php echo $after_widget; } 

That is, as you can see, there are no syntax errors. Maybe it's in the PHP settings? What parameters are responsible for the syntax check?

Closed due to the fact that participants are off topic Alexey Shimansky , aleksandr barakin , Grundy , Pavel Mayorov , D-side 19 Apr '16 at 13:29 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Alexey Shimansky, aleksandr barakin, Grundy, Pavel Mayorov, D-side
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • In the sense of no syntax errors if you <?php echo $after_widget; and then immediately } ...... and inside suddenly echo $before_widget; ?> echo $before_widget; ?> and this is called no error? And on lokalkhost everything worked apparently because you turned off any error mapping .......... and in general this function is for javascript or for php? - Alexey Shimansky
  • @ Alexey Shimansky tin, which you won't see only on SO)))) For some reason in my manuals (when I studied php) this was not the case) - Vasily Barbashev
  • one
    @Bogdan at least ?> Put after <?php echo $after_widget; (closing interpreter tag) - Vasily Barbashev
  • @ Vasily Barbashev to get two more bugs: parsing error + left closing bracket on the output? I pointed out the problem in this comment - BOPOH

3 answers 3

  1. at the beginning of the code there is no opening <?php tag, but since this is a fragment, it probably is higher in your code;
  2. perhaps the hosting does not include the use of short tags <? , change them to <?php ;

    The problem is really echo:

     echo $before_widget; echo $after_widget; 

    ... because it should be displayed like this:

     echo $args['before_widget']; echo $args['after_widget']; 

    what I learned in the example on developing widgets for wordpress. That is, the whole function looks like this:

     public function widget( $args, $instance ) { echo $args['before_widget']; if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title']; } echo __( 'Hello, World!', 'text_domain' ); echo $args['after_widget']; } 

    Interestingly, PHP 5.4 is not outraged by the presence of such an error.

    • one
      Maybe because you have disabled the display of errors, but not on the hosting? - Alexey Shimansky
    • Doesn't extract() bother you? His job is precisely this: to get the values ​​specified there from the array into the local variables. Those. after extract($args); you can write echo $before_widget; instead of echo $args['before_widget']; - BOPOH
    • and the problem you most likely is that the hands must be cut off by the one who wrote it. <? endif ?> <? endif ?> - what is it? A semicolon does not seem to be necessary (although it is necessary to give a hand too), but using short tags instead of simple ones (or whatever they are) is fraught with cutting off hands to the ears, here even grep -Pr '<\?[^p=]' * will not save. Hosting most likely did not allow their use, because everything worked on localhost, but not here - BOPOH
    • @BOPOH - half woes echo ...... if you write echo $args['before_widget']; then the question arises, where do html tags come from without echo ? Or is it just confusing me? ...... In general, everything is a complete kapets - Alexey Shimansky
    • @ Alexey Shimansky, this is normal, especially if you remember how php appeared. Anything between ?> And <?php can be conditionally considered as echo '...' - BOPOH

    Use IDE such as PhpStorm Here is the IDE that highlighted the error

    • extract() does not confuse you? but because of him, this is exactly what works as it should, the problem is different - see other answers or my comment to the author's answer - BOPOH
    • @BOPOH Thank you! Got it! - Nicolas Chabanovsky