Page 1 of 1

Calling classes and functions

Posted: Sun Aug 19, 2007 5:38 am
by kkonline
I have a variable as

Code: Select all

$subject=$_POST['subject']


then how do i call a class (so all functions are executed within it) and how to call individual function of the class. I want to pass $_POST['subject'] to the class / function

The name of the class is

Code: Select all

class popoon_classes_externalinput
and it contains two functions

Code: Select all

static function basicClean($string) and static function removeMagicQuotes($data)

Posted: Sun Aug 19, 2007 7:26 am
by Oren
Add a constructor to this class, pass your variable to the constructor, and make the constructor call the other 2 methods you have in this class:

Adding a constructor:

Code: Select all

public function __construct($data)
{
	// Asuming that removeMagicQuotes() and basicClean() are mutators
	self::removeMagicQuotes($data)
	self::basicClean($data)
}
Creating a new instance of the class + passing $subject to the class:

Code: Select all

$my_class = new popoon_classes_externalinput($subject);
Edit:

P.S Note that this code is really basic and I skipped/omitted several VITAL parts. I simply assumed that you'll figure it out by yourself. If you can't, just ask here :wink: