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

Objects in PHP Forum

View Course » View Exercise

441 points
Picture
Submitted by
Tom B.
over 2 years ago

Unexpected T_Variable 9/10

Hi!
For some reason I keep getting this error through the excercices. Eventhough if I click next it will work.
And i've been going through my code but can't find out why i keep getting: Parse error: syntax error, unexpected TVARIABLE, expecting TFUNCTION on line 24 // Line 24 is the $cat1 = new Cat("CodeCat");

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


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

              }
              function meow(){
                  return "Meow meow";
              }
 $cat1 = new Cat("CodeCat");
 $cat1->meow();

 echo $cat1;

It would be awesome if someone could help me out with this.
Thank you in advance!


1 vote

permalink

Try moving the function Meow inside the Cat class:

class Cat{

Public var

function __construct(){}
function meow(){}
}

805 points
9b3e42b32c59734062d1f22641acbced?s=140&d=retro
Submitted by
Daniel Wright
over 2 years ago