Are Magic Methods Best practice in PHP?
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.
I don’t think magic methods are best or worst practice: depending on what you want to achieve you can use them or not…
What I mean is that you don’t have to tweak your code as possible to use them, but if you have to there is no problem at all.
If you have an object with 3 and only 3 attributes you don’t need to use magic setters/getters, but in some advanced cases they are a great way to do very complex things (ORM systems etc…)
Maybe some of them are deprecated, I don’t know, but most of them are not.