0

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!

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Should adding the __construct() { $a = 'b'; } help?
I have no idea what $a ='b'; is supposed to do, but whatever.
I mean something abstract. As I am not sure I am allowed to create abstract constructor method
Seems like it would be easier to rename your errant function than create an empty useless constructor you don't need.
If you rename isolate then you will no longer have a constructor method.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.