Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialrob111
8,379 PointsWhy are we not using the __get() and ___set() Magic Methods?
Throught this course we are using setTitle() and getTitle() methods for example but isn't that what these Magic Methods are for? Am I missing something?
Why are we not using the __get()
and __set()
Magic Methods?
2 Answers
Greg Kaleka
39,021 PointsHey Rob,
No, that's actually not what __get()
and __set()
are for. Check out this StackOverflow answer. These magic methods are for use when you cannot access the property directly (i.e. it's a private property out of scope). You should typically be using actual getter and setter methods like setTitle() and getTitle().
Cheers
-Greg
rob111
8,379 PointsGreg Kaleka can you shed some light on this?
Boon Kiat Seah
66,664 PointsBoon Kiat Seah
66,664 Pointsneed to look into this questions too. Have this on my mind as well.