PHP - OOP - Why is my function called twice?

前端 未结 5 1143
逝去的感伤
逝去的感伤 2021-01-17 05:00

I\'m facing a problem that my function is called twice everytime i submit my form

my form file with the call to the function:



        
5条回答
  •  迷失自我
    2021-01-17 05:54

    When you create a Class, you should specify a Constructor.

    If you dont specify a Constructor, it's called by Magic Methods.

    In Your Case, you create a Class Without a constructor, by with a function with the same name of the Class. Class Login -> Method Login. The PHP Acts like the Login Method is your constructor...

    So when you call $login = new Login() you are calling the constructor that's the Login Method.

    And when you call Login Method, $login->login(), you are calling it twice.

    Are you understood?

提交回复
热议问题