Can changing if formats cause “Parse error: syntax error, unexpected $end”?

I’m fairly new to PHP and I’ve been teaching myself mostly by editing files on a test site that’s a duplicate of our live site. We are wanting to upgrade our WordPress site and all our plugins because it’s nearly 6 years out of date. The person who made the site put in lots of custom code without making a child theme, so I duplicated the live site and upgraded everything. Now, there are a few tweaks I need to make in order to keep the functionality we had before. All of those changes are done except for this last PHP file.

I’ve scoured the file a dozen times by now but I haven’t been able to find an open bracket anywhere. I tried testing by deleting several sections and using the PSPad function to find a matching bracket, but I continue to get the same error. One of my concerns is that the file uses if statements with : sometimes, but other times it uses {}. Can this cause confusion on the server?

Read More

I realize this file is rather large, but if anyone has any advice or help they could provide I’d greatly appreciate it. Thanks for your time.

EDIT
I’ve posted my revised code in which I found a few if statements that were missing : and a few missing and extra endif statements. Thanks to both of you who helped me locate these.

<?php

/**

 * Property Default Template for Single Property View

 * Modified by RJA for APM

 * Overwrite by creating your own in the theme directory called either:

 * property.php

 * or add the property type to the end to customize further, example:

 * property-building.php or property-floorplan.php, etc.

 *

 * By default the system will look for file with property type suffix first,

 * if none found, will default to: property.php

 *

 * Copyright 2010 Andy Potanin <andy.potanin@twincitiestech.com>

 *

 * @version 1.3

 * @author Andy Potanin <andy.potnain@twincitiestech.com>

 * @package WP-Property

*/



// Uncomment to disable fancybox script being loaded on this page

//wp_deregister_script('jquery-fancybox');

//wp_deregister_script('jquery-fancybox-css');

?>

<?php get_header(); ?>

<?php the_post(); ?>



    <script type="text/javascript">

    var map;

    var marker;

    var infowindow;



    jQuery(document).ready(function() {



      if(typeof jQuery.fn.fancybox == 'function') {

        jQuery("a.fancybox_image, .gallery-item a").fancybox({

          'transitionIn'  :  'elastic',

          'transitionOut'  :  'elastic',

          'speedIn'    :  600,

          'speedOut'    :  200,

          'overlayShow'  :  false

        });

      }



      if(typeof google == 'object') {

        initialize_this_map();

      } else {

        jQuery("#property_map").hide();

      }



    });





  function initialize_this_map() {

    <?php if($coords = WPP_F::get_coordinates()) : ?>

    var myLatlng = new google.maps.LatLng(<?php echo $coords['latitude']; ?>,<?php echo $coords['longitude']; ?>);

    var myOptions = {

      zoom: <?php echo (!empty($wp_properties['configuration']['gm_zoom_level']) ? $wp_properties['configuration']['gm_zoom_level'] : 13); ?>,

      center: myLatlng,

      mapTypeId: google.maps.MapTypeId.ROADMAP

    }



    map = new google.maps.Map(document.getElementById("property_map"), myOptions);



    infowindow = new google.maps.InfoWindow({

      content: '<?php echo WPP_F::google_maps_infobox($post); ?>',

      maxWidth: 500

    });



     marker = new google.maps.Marker({

      position: myLatlng,

      map: map,

      title: '<?php echo addslashes($post->post_title); ?>',

      icon: '<?php echo apply_filters('wpp_supermap_marker', '', $post->ID); ?>'

    });



    google.maps.event.addListener(infowindow, 'domready', function() {

    document.getElementById('infowindow').parentNode.style.overflow='hidden';

    document.getElementById('infowindow').parentNode.parentNode.style.overflow='hidden';

   });



   setTimeout("infowindow.open(map,marker);",1000);



    <?php endif; ?>

  }



  </script>


  <div id="container" class="<?php echo (!empty($post->property_type) ? $post->property_type . "_container" : ""); ?>">

    <div id="content" role="main" class="property_content">

      <div id="post-<?php the_ID(); ?>"<?php post_class(); ?>>

      <div class="building_title_wrapper">

        <?php if ($post->property_type == 'building') : ?>
          <h1 class="property-title entry-title"><?php echo $post->building_name; 
          endif;          
          ?></h1>

        <?php
// Define Retail Address - JC
      $RetailAddress = explode(' ',$post->address);
      $RetailAddress1 = explode(',',$RetailAddress[3]);
      $RetailAddress = $post->suite." ".$RetailAddress[1]." ".$RetailAddress[2]." ".$RetailAddress1[0];    
// Define Mytype - JC                    
          $mytype = " (".ucwords($post->property_type).")";
// Define Childname - JC            
          switch($post->property_type) {
            case 'office':
            $childname = "Suite ".$post->suite.$mytype;
          break;
            case 'industrial':
            $childname = "Space ".$post->suite.$mytype;
          break;
            case 'retail':
            $childname = $RetailAddress." ".$mytype;  
          break;
      }
          ?>         
          <h1 class="property-title entry-title"><?php echo $childname; ?></h1>

      </div>


      <div class="entry-content">

          <div class="wpp_the_content"><?php @the_content(); ?></div>

        <?php if ($post->property_type<>'building') : ?>
          <div class="wpp_the_content"><a href="<?php echo $post->parent_link; ?>"><b><?php echo $post->parent_title; ?></b></a></div>
          <br>
        <?php endif; ?>

        <?php if ( empty($wp_properties['property_groups']) || $wp_properties['configuration']['property_overview']['sort_stats_by_groups'] != 'true' ) : ?>
        <?php endif; ?>

<!-- The line below paints the list of attributes -->
        <?php
       if($property['property_type']=='building')   
        //@draw_stats("make_link=true&exclude=area,property_no,available,city,building_type&sort_by_groups{$wp_properties['configuration']['address_attribute']}");
          {echo @draw_stats('display=list&class=property_stats&exclude=area,property_no,available,city,building_type&sort_by_groups=false', $property );}
        elseif ($property['property_type']=='industrial')
          {echo @draw_stats('display=list&class=property_stats&exclude=whprice,property_no,available,unit_no,city,parent_gpid&sort_by_groups=false', $property );}  
        else
          {echo @draw_stats('display=list&class=property_stats&exclude=whprice,property_no,available,unit_no,city,parent_gpid&sort_by_groups=false', $property );}
        ?>          

         </dl>          
<!-- End attribute painting -->

   <?php if ($post->property_type == 'building') : ?>

   <!-- if a flyer exists, display link here -->
          <?php
          $myproperty = $post->property_no;
          $mypath = "flyers/".$myproperty.".pdf";
          // echo "Looking for ".$mypathn;
          if (is_file($mypath)):
          ?>
            &nbsp;&nbsp;
            <a href="http://lease.apmportland.us/<?php echo $mypath; ?>" target="_blank">View Flyer</a>
            &nbsp;(Opens in a new window and requires Adobe Reader)<br>&nbsp;<br>
          <?php endif; ?>

    <?php endif; ?>

<!-- Begin the Community Features section -->         



<!-- Begin the map section -->

        <?php if(WPP_F::get_coordinates()): ?>

          <div id="property_map" style="width:100%; height:450px"></div>

        <?php endif; ?>



        <?php if(class_exists('WPP_Inquiry')): ?>

          <h2><?php _e('Interested?','wpp') ?></h2>

          <?php WPP_Inquiry::contact_form(); ?>

        <?php endif; ?>

<!-- End map section -->    

<!-- Begin space plan section -->

        <?php
          $myunit = $post->unit_no;
          $mypath = "spaceplans/".$myunit.".jpg";
          if (is_file($mypath)): ?>
            <img src="http://lease.apmportland.us/<?php echo $mypath; ?>">
            <BR>&nbsp;<BR>
            <?php echo "Note: space plan not to scale." ?>
          <?php else: ?>
            <img src="http://lease.apmportland.us/spaceplans/blank.jpg">
          <?php endif; ?>


        <!-- End space plan section -->       

      </div><!-- .entry-content -->

    </div><!-- #post-## -->



    </div><!-- #content -->
    <a href="javascript:history.go(-1)"><b>Previous page</b></a>

  </div><!-- #container -->


<?php

  // Primary property-type sidebar.

  if ( is_active_sidebar( "wpp_sidebar_" . $post->property_type ) ) : ?>



    <div id="primary" class="widget-area <?php echo "wpp_sidebar_" . $post->property_type; ?>" role="complementary">

      <ul class="xoxo">

        <?php dynamic_sidebar( "wpp_sidebar_" . $post->property_type ); ?>

      </ul>

    </div><!-- #primary .widget-area -->


<?php endif; ?>


 <?php get_footer(); ?>

Related posts

1 comment

  1. I’ll start with this, you’re better off using a switch/case statement from line 177 where you check out the $post->property_type:

    switch($post->property_type) {
        case 'office':
        $childname = "Suite ".$post->suite.$mytype;
        break;
        case 'industrial':
        $childname = "Space ".$post->suite.$mytype;
        break;
        case 'retail':
        $childname = $RetailAddress[0]."".$mytype;
        break
    }
    

    Now for the error. There seems to be a few. The first one is this where you’re missing a closing >:

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    

    Source: Line 157

    And you also have this if block that isn’t being closed off anywhere in the code:

    <?php if ( empty($wp_properties['property_groups']) || $wp_properties['configuration']['property_overview']['sort_stats_by_groups'] != 'true' ) : ?>
    

    Source: Line 199

    And also this if here where you’re missing a closing endif; again:

    <?php if ($post->property_type == 'building') : ?>
    

    Source: Line 239

    You have this if line without opening it properly or closing it, you should change this code block:

    <?php if(is_array($wp_properties['property_meta'])): ?>
    
    <?php
    foreach($wp_properties['property_meta'] as $meta_slug => $meta_title):
    
    if(empty($post->$meta_slug) || $meta_slug == 'tagline'):
    
    continue;
    ?>
    
    <h2><?php echo $meta_title; ?></h2>
    
    <p><?php echo do_shortcode(html_entity_decode($post->$meta_slug)); ?></p>
    
    <?php endif; ?>
    <?php endforeach; ?>
    
    <?php endif; ?>
    

    Source: Lines 270 to 288

    That’s what I could pick up while having a quick browse. Remember, if you’re going to use the templating if / endif you always need to do it like this:

    if(CONDITION) :
        // do stuff
    endif;
    

    You can’t forget the : in the if statement. (Which you’ve done in your code)

Comments are closed.