Shashank Jain
Shashank Jain

Reputation: 857

Why no Output in PHP OOP program?

<?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.

Upvotes: 1

Views: 107

Answers (1)

Decent Dabbler
Decent Dabbler

Reputation: 22773

The proper name for the constructor is __construct, not __constructor

Upvotes: 11

Related Questions