Total beginner Object Oriented problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Total beginner Object Oriented problem.

Post 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?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Total beginner Object Oriented problem.

Post by Eran »

You need to call class functions the same as you call class properties - using the '$this' scope.

Code: Select all

$this -> calculateSquare()
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Total beginner Object Oriented problem.

Post by klevis miho »

Thanks pytrin :)
Post Reply