This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by jester2799
over 10 years

Why am I getting the error parse error: syntax error, unexpected '{' on line 18?

I have no idea why I’m getting this error. I don’t see any missing or misplaced brackets. I have the usual html, head, and title tags at the top, but I can’t get them to show up for some reason. Here’s my code:

Answer 521bc01d548c35d1dd000376

6 votes

Permalink

// Not sure as this works ok, as i just tested and passed with my code below.(i dont see a diff in your code). Try refreshing the page or submitting a few times etc.

 <?php
        class Shape {
          public $hasSides = true;
        }
        
        class Square extends Shape {
        
        }
        
        $square = new Square();
        // Add your code below!
        if (property_exists($square, "hasSides")) {
          echo "I have sides!";
        }
      ?>
points
Submitted by Tj Martinez
over 10 years

2 comments

Tj Martinez over 10 years

I also noticed that instead of using the property_exists method, there is a quicker way to get the same result by using “” if ($square->hasSides)”””…

However the example cleary wants us to use the property_exists method instead (to pass the section)

jester2799 over 10 years

Thanks guys, problem solved!

Answer 525dc862abf821aec50002b1

5 votes

Permalink

In line 18 you didnt closed the bracket of property_exists. Try that…You will get the correct answer..!!

points
over 10 years

1 comments

Abner about 10 years

Just a pair of () and the whole thing doesn’t work =P

Answer 523a39beabf8211b53002723

0 votes

Permalink

Not sure if this helps, being so late and all but I noticed your missing a ) in your if statement

you have if (property_exists($square, “hasSides”)

not if (property_exists($square, “hasSides))

points
Submitted by 0501188
over 10 years

Answer 5505c40595e37873ef006745

0 votes

Permalink

This worked for me just now; Using Waterfox 35.0

  <?php
    class Shape {
      public $hasSides = true;
    }
    
    class Square extends Shape {
    
    }
    
    $square = new Square();
    // Add your code below!
    if (property_exists($square,'hasSides')) {
      echo "I have sides!";
    }
  ?>
points
Submitted by samalkobi
about 9 years

Answer 55d970449376762b8e000425

0 votes

Permalink

the answer was really simple he missed to close the bracket.. why try this and this worked for me..lol

points
Submitted by Sushil Gamre
over 8 years