开发者

syntax error, unexpected '}' [closed]

开发者 https://www.devze.com 2023-04-08 19:38 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I am at a loss and I've spent a few weeks reading site after site to try and understand what I can do. The problem is that I am learning as I have been doing since I have a website - mostly the hard way. ;)

I would be very grateful if you can help me.

This error is related to wp-content/plugins/color-widgets/colorwidgets.php

Above the line (53 in this case) is:

}

              <?php }
              } ?>      
              <div style="background-color:<?php echo $textbgcolor; ?>; color:<?php echo $textfontcolor; ?>; text-align:<?php echo $texthalign; ?>; padding:<?php echo $textpadding; ?>"><?php echo $text; ?></div>
          <?php if ($themestyle == 'Yes') { echo $after_widget; } ?>
    </div>
    <?php

**The } is in the line under <?php.

Underneath } is:**

  /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {             
        return $new_instance;
    }

**I deleted the } but syntax error, unexpected '}' still exists when I try to access my site, so I put it back.

.............. I then added admin to the end of URL and got a different message.

Fatal error: Class 'ColorWidgets' not found in /wp-includes/widgets.php on line 324

The line is (below):**

$this->widgets[$widget_class] = & new $widget_class();

Above this is:

/**                             
 * Singleton that registers and instantiates WP_Widget classes.                             
 *                              
 * @package WordPress                               
 * @subpackage Widgets                              
 * @since 2.8                               
 */                             
class WP_Widget_Factory {                               
    var $widgets = array();                         

    function WP_Widget_Factory() {                          
        add_action开发者_开发知识库( 'widgets_init', array( &$this, '_register_widgets' ), 100 );                        
    }                           

    function register($widget_class) >{                         
        $this->widgets[$widget_class] = & new widget_class();                       

The last line is the error line, and below is:

}                           

function unregister($widget_class) >{                           
    if ( isset($this->widgets[$widget_class]) )                     
        >unset($this->widgets[$widget_class]);                  
}                           

.............

I apologise for the amount of time needed to follow my post and I'd greatly appreciate feedback. Thank-you for listening. :)


This error indicated that you have more closing brances. To fix it, you have to scroll through your code the check where the problem is.

Next time, when developing, try to always add opening and closing braces before actually filling it with code and try to indent and format your code like this, so that you will minimize the same error and potentially another error / bug:

if()
{
   if()
   {
      if()
      {

      }
   }
}

instead of

if(){
   if(){
      if()
{


      }
}
}

or

<?php

if()
{
?>
<!-- your code-->
<?php
}

?>

instead of

<?php

if(){
?>
<!-- your code--><?php}

?>

It would also be better if you have editor that support formatting source-code. I use Netbeans for this.


In essence the error is saying you have more closing braces than opening ones. Double check you braces and you'll probably find they don't match.

UPDATE:

Fix one error at a time. If you were still getting "Unexpected }" don't add something else until you've fixed that error.


First of all, try to make sure you have paired ALL the braces in the code.

Second, if this isn't working, check to see if you have missed some trailing semicolons in the code. This can be easily done if you have a regex-enabled search function in your IDE and a well-implemented writing style.

I would check for the second one first, but this is my case only.

Wishing you best of luck,

Victor

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号