Since my tech book told me, so I am thinking that this is true, for example:
square A {public $ attr = "hmm"; } $ A = new A (); Echo $ a-> ether; // output Hmm works well for me, the book is not that it is not making a __get function in order to use it outside the classroom, I'm a little confused
both public variables and magical __get (< / Code> Methods are considered to be a poor behavior First of all, objects have to be piled up to pile up objects, whereas magic Getters / Setters attract complexity. Some operations on the data in Setter are common, before the parameters, for example, you will validate the email address. Or format of phone number Instead, when you use the magical __ go and __set methods, then you have to do all this in one method. In fact, your magical setter turns a large cluster of different depth * uck's if .. and statement. Instead you should create a custom paragraph for the example parameters that you want to manipulate:
class book {Private $ title; Private $ author; Public function __ composition ($ author = null, $ author = null) {$ this- & gt; Title = $ heading; $ The-> author = $ author; } Public Function Settle ($ title) {$ this- & gt; Title = $ title; } Public Function Set Writer ($ author) {$ this- & gt; Author = $ author; }} used as:
$ example = new book ('gym butcher'); $ Isntance- gt; SetTitle ('Fool's Moon');
No comments:
Post a Comment