Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse error: syntax error, unexpected T_Class in Box.php

Status
Not open for further replies.

peterv12

Technical User
Joined
Dec 31, 2008
Messages
108
Location
US
I'm attempting to learn OOP PHP using a tutorial I found on the web. I'm running the code in an OS X terminal. The code is:
Code:
<? php

   class Box
   {
      var $contents;

   function Box($contents) {
      $this->contents = $contents;
   }

   function get_whats_inside() {
      return $this->contents;
   }
}

$mybox = new Box("Jack");
echo $mybox->get_whats_inside();

?>
When I run it, I get this error:
Code:
Parse error: syntax error, unexpected T_CLASS in Box.php on line 3

This code was copied exactly from the tutorial, so I thought it should work. Can anyone help me out?
Thanks,
Peter V.
 
there should be no space between <? and php
 
Duh! brain-cramp! Thanks....
 
be careful about using method names that are identical to the class name. shortly this will not be acceptable as a de facto constructor.
 
Thanks j! I'll definitely make a note of this, and change my code.
Peter V.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top