Hello Everyone,
I’m new to PHP programming and I’d like your assistance. I’m trying learning about classes. I wrote the following script and create a new object, all in the same file, however, after running it i get the following error message: Parse error : syntax error, unexpected ‘}’ in C:\Users\bgeor\Desktop\WebServer\classTest1.php on line 9.
Double checking on my script it seems everything is fine (obviously it’s not, since i keep on getting the same error). Thanks
<?php
class Rectangle {
//Declare properties
private $length=0;
private $width=0;
//Method declaration
function getPerimeter() {
return (2*($this->length + $this->width))
}
//Method to get the area
function getArea(){
return ($this->length*$this->width)
}
//Create new object from Rectangle class
$rect = new Rectangle;
//Get the object property value
echo $rect->length;
echo $rect->width;
//Set object property values
$rect->length=30;
$rect->width=20;
//Call the object methods
echo $rect->getPerimeter();
echo $rect->getArea();
}
?>