Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my constructor still called even if the class and constructor case are different?

I am surprised for why the constructor is called when we have different class and constructor name. Constructor name is starting with small "r"?

class Registration{

    function registration(){
        echo "Constructor is called.";
    }
}

$obj = new Registration();
//$obj->registration();

Outputs: Constructor is called.

Modification: Does this case-insensitive behavior depends on php versions we are using?

like image 543
Ghazanfar Mir Avatar asked Dec 10 '22 05:12

Ghazanfar Mir


1 Answers

php is case-insensitive (sometimes). The following would work as well:

CLASS REGISTRATION {

    FUNCTION reGISTration(){
        ECHO "constructor is called.";
    }
}

$obj = NEW Registration();
like image 61
user187291 Avatar answered Dec 11 '22 18:12

user187291