This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course » View Exercise

578 points
512f1f341ff4e76cdd00a132_929539431
Submitted by
Ruhi Mukherjee
over 3 years ago

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION on line 26

My Code is getting submitted but is showing the error on line 26th

<!DOCTYPE html>


Challenge Time!




<?php
// Your code here
class Cat
{
public $isAlive = true;
public $numLegs = 4;
public $name;

          public function __construct($name)
          {
              $this->name = $name;
          }

          public function meow()
          {
              return "Meow meow";
          }
          $cat1 = new Cat("CodeCat");  //line 26
          echo $cat1->meow();
      }
    ?>
  </p>
</body>

3 votes

permalink

It seems you are executing your $cat1 creation WITHIN the class definition itself.
Execute the code AFTER the closing-curly-bracket-for-the-class-definition AND before the closing PHP with "?>"

3645 points
5334fc819c4e9db930001a0d_32139218
Submitted by
Leon
over 3 years ago

1 Comment

E39786f437da6f566327b05ebf08c600?s=140&d=retro akash almost 3 years ago

Thanks