1
<?php

class TrimPHP_Strings {    
    public $str;

    public function Apply() {    
            return $this->str;
    }

    function __constructor($str) {    
        $this->str = $str;
    }

}

function Strings($str) {
    $obj = new TrimPHP_Strings($str);
    return $obj;
}
?>
<?php    
echo Strings("My String")->Apply();
?>

I can not understand why the above code doesn't work? I expect it to output My String but it simply outputs a blank page.

0

1 Answer 1

11

The proper name for the constructor is __construct, not __constructor

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

2 Comments

Argh... Always fell like an idiot when I make such stupid mistakes. Thanks for the correction.
I know the feeling all too well Shashank ;-)

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.