0

getting error "Parse error: syntax error, unexpected '$physics' (T_VARIABLE), expecting function (T_FUNCTION) in C:\xampp\htdocs\bookclass.php on line 19"need help pls help me out.

<?php
class  Books{
    /* Member variables */
    public $price;
    public $title;
    /* Member functions */
    function setPrice($par){
       $this->price = $par;
    }
    function getPrice(){
       echo $this->price ."<br/>";
    }
    function setTitle($par){
       $this->title = $par;
    }
    function getTitle(){
       echo $this->title ." <br/>";
    }
  $physics = new Books;
  $physics->setTitle( "Physics for High School" );
  $physics->setPrice( 10 );
  $physics->getTitle();
  $physics->getPrice();
}
?>
3
Contributors
3
Replies
22
Views
2 Years
Discussion Span
Last Post by Gideon_1
0

In line 19 you have code inside the class but outside any method . Probably you meant to close the class first and then use it.

0

I don't know whether your codes are just for training purposes but for production purposes declare the state of your methods, be it, public, private or protected

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.