PHP - OOP - Why is my function called twice?

前端 未结 5 1138
逝去的感伤
逝去的感伤 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:46

    A method named the same as the class is considered an (old style) constructor, and is called every time the object is created.

    So it's called once when the object gets created, and another time when you explicitly call it.

    Note that today, it's considered a better practice to implement __construct() rather than ClassName(), mainly to help with inheritance.


    More reading material:

    • PHP - Constructors and Deconstructors
    • PHP - Old Style Constructors

提交回复
热议问题