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

463 points
0a33e29808d1bb9f9130b93e7c3b6365?s=140&d=retro
Submitted by
James Barclay
over 5 years ago

Confusing error with PHP objects - Unexpected T_VARIABLE, expecting T_FUNCTION

Whenever I create a new instance of an object I receive this error:

Parse error: syntax error, unexpected TVARIABLE, expecting TFUNCTION on line ...(in the example to come, line 10)

The code passes each task, however I just wanted to know whether this is actually a legitimate error in how I'm writing the code or whether it is a error not related to me. Below is the simplest code I have done that still produces the error.

    <html>
  <head>
    <title>OOP Review</title>
  </head>
  <body>
    <p>
      <?php
    class Person{
          $me = new Person();
      }          
      ?>
    </p>
  </body>
</html>`

1 vote

permalink

You're supposed to create the instance outside of the class:

class Person{

  }

$me = new Person();

322 points
065d2765d944a1e8ca3253a1ca860c47?s=140&d=retro
Submitted by
DM
over 5 years ago