How can I call following Class method or function?
Let say I have this params get from url:
$var = filter($_GET['params']);
Class:
class Functions{
public function filter($data){
$data = trim(htmlentities(strip_tags($data)));
if(get_magic_quotes_gpc())
$data = stripslashes($data);
$data = mysql_real_escape_string($data);
return $data;
}
}
thanks.
This way:
You need to create
Object
for theclass.
Create object for the class and call, if you want to call it from other pages.
Or inside the same class instances [ methods ], try this.
Have a look at the PHP manual section on Object Oriented programming
As th function is not using
$this
at all, you can add astatic
keyword just after public and then callAvoiding the creation of an object just for one method call
Within the class you can call function by using :
Outside of the class
you have to create an object of a class
for more about OOPs in php
this example:
hope it will help!