Reputation: 595
I try to create new object of a class called Isolate (this class is used to prevent XSS and other attacks via htmlspecialchars and so on).
So, I do it like this:
$data['name'] = $_POST['name'];
$data = $isolate->isolateArr($data);
And my Isolate class look like this:
class Isolate {
public function isolate($var) {
$iVar = htmlspecialchars($var);
$iVar = mysql_real_escape_string($iVar);
$iVar = stripcslashes($iVar);
return $iVar;
}
public function isolateArr($arr) {
foreach($arr as &$instance) {
$instance = $this->isolate($instance);
}
unset($instance);
return $arr;
}
But as the result I have a warning like Missing argument 1 for Isolate
. As I understand, it asks me for the argument for the first function, but I do not need to call the first one, I need to call the second (because I have an array in this case).
So, why does it always ask for the first function argument? There in no any __construct
method, what is the point?
Thank you in advance!
Upvotes: 0
Views: 83
Reputation: 7005
isolate()
is your constructor method.
http://www.php.net/manual/en/language.oop5.decon.php
For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, and the class did not inherit one from a parent class, it will search for the old-style constructor function, by the name of the class.
Upvotes: 6