I’m new to PHP OOP, and I think public $var and __construct() are exactly the same.
What’s the difference? Which one should I use?
I’m new to PHP OOP, and I think public $var and __construct() are exactly
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are completely different things: one declares a class property, and the other is the name of the class constructor.
There is no such thing as “one or the other” here.
I suggest re-reading all about classes and objects in your PHP book, or the manual.