Page 1 of 1

Total beginner Object Oriented problem.

Posted: Sat May 22, 2010 6:26 am
by klevis miho
I'm beginning object oriented php, and now I'm stuck at this piece of code:

Code: Select all

<?php

class intSquare {

	private $squareValue;

	private function calculateSquare($val) {
	
		return $val*$val;
		
	}
	
	public function getSquare($value) {
	
		$this->squareValue = calculateSquare($value);
		return $this->squareValue;
		
	}
	
}


$object = new intSquare();

echo $object->getSquare(4);

?>
The error is: Fatal error: Call to undefined function calculatesquare() in C:\xampp\htdocs\oo\class_intSquare.php on line 15

What have I done wrong here?

Re: Total beginner Object Oriented problem.

Posted: Sat May 22, 2010 6:38 am
by Eran
You need to call class functions the same as you call class properties - using the '$this' scope.

Code: Select all

$this -> calculateSquare()

Re: Total beginner Object Oriented problem.

Posted: Sat May 22, 2010 6:40 am
by klevis miho
Thanks pytrin :)