Calling classes and functions

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Calling classes and functions

Post 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)
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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:
Post Reply