2016-12-05 2 views
-1

Ich bin zu Php OOPs Konzept neu .. ich versuche, einen Buchnamen in einer Tabelle (index.php) zu drucken, die die Buchdetails in der unterschiedlichen Klassendatei sind (FirstExample.php) .Ich habe Parse-Fehler in der Klasse file.I meinen Code zu überprüfen twice..But ich verstehe nicht Fehler, den ich gemacht haben ..Parserfehler: unerwartete (T_variable) Erwartungsfunktion (T_FUNCTION)

<?php 
class FirstExample { 
var $book; 
var $price; 
public function getBookName($bookname){ 
    $this->book = $bookname; 
    echo "The bookname you Ordered is $book"; 
} 
public function getBookPrice($bookPrice){ 
    $this->price = $bookPrice; 
    echo "The Book Price is $price"; 
} 
$physics = new FirstExample; 
$chemistry = new FirstExample; 
$Mathematics = new FirstExample; 
$computerProgramming = new FirstExample; 
$physics->getBookName("Physics"); 
$physics->getBookPrice("$150"); 
$chemistry->getBookName("Chemistry"); 
$chemistry->getBookPrice("$100"); 
$Mathematics->getBookName("Mathematics-Differential and Integral Calculas"); 
$Mathematics->getBookPrice("$200"); 
$computerProgramming->getBookName("Advanced Computer Programming"); 
$computerProgramming->getBookPrice("$200"); 
} 
?> 
+1

Schließen Sie die Klasse mit '}' 'nach getBookPrice 'definition –

+1

move} unter der Funktion getBookPrice (....) ... um deine Klassendefinition zu schließen – donald123

+0

danke @ donald123 und @ Nordenheim – Madhi

Antwort

1
<?php 
//class starts here 
class FirstExample { 

private $book;// use private|protected|public (public is default) keyword not var in class 
private $price; 

    public function getBookName($bookname){ 
     $this->book = $bookname; 
     echo "The bookname you Ordered is $this->book";// if variable is private the use $this->variable_name to access it in side of class 
     // out side of class protected variable is not accessable. 
    } 

    public function getBookPrice($bookPrice){ 
     $this->price = $bookPrice; 
     echo "The Book Price is $this->price"; 
    } 
}//class ends here 
$physics = new FirstExample; 
$chemistry = new FirstExample; 
$Mathematics = new FirstExample; 
$computerProgramming = new FirstExample; 
$physics->getBookName("Physics"); 
$physics->getBookPrice("$150"); 
$chemistry->getBookName("Chemistry"); 
$chemistry->getBookPrice("$100"); 
$Mathematics->getBookName("Mathematics-Differential and Integral Calculas"); 
$Mathematics->getBookPrice("$200"); 
$computerProgramming->getBookName("Advanced Computer Programming"); 
$computerProgramming->getBookPrice("$200"); 

?> 
+0

vielen Dank .. :) @viral barot – Madhi

Verwandte Themen