Jump to content
Larry Ullman's Book Forums

Ch4, Quesions On 'magic Methods' And More


Recommended Posts

Larry,

I am reading CH4 the second time, and have a couple of questions:

1.
I noticed that in Ch4 when introducing constructors, __autoload, and the like, you wrote 'note that functions in PHP beginning with two underscores are special ones'.  Why not just use the term 'magic methods' for those special ones?

2.
When introducing $this, it states 'you must use an alternative syntax to access the class’s attributes.'  Will it be better to indicate that PHP requires an explicit $this to be used when we access class members in the class? Because many OO languages like C++, C# or Jave do not enforce $this(correct me if I am wrong)?

 

Also, I think 'to access the class's members' would be better than "class's attributes".

 
3. In the last tip of Creating Constructor section it mentions the PHP 4 constructor naming scheme, why does PHP constructor have such change? My guess is, for PHP 4 style:

class Human {
public Human() {    // PHP 4 constructor

}

}

then when the class name is changed later somehow, we have to also update the constructor name; so to use __construct eliminates such issue. Is my guess right?
 

Link to comment
Share on other sites

One of the caveats of Larry's ability to translate Geek into English is that some of the geek gets left out. (willingly) Way to many writers are too hung up in definitions and technical phrasing that their explanations gets unnecessary complicated. Don't get to hung up in that the phrasing might be slightly different than the common technical terminology. That is often what drives the point true.

 

----

 

2. You are correct about $this. You can choose to skip this.property or this.method() in both Java and C#. The same applies to constants and static methods and members. I would've liked to be able to leave them out myself, as $this and self:: are mostly noise words in your code anyway. I hope they become optional some day.

 

3. I think they did this to explicitly separate PHP 4 and PHP 4.3 object-orientation. At that time, PHP did not even have access modifiers (public, protected, etc) and I think they did things a little differently for compatibility reasons between versions. That is what I recall to have read sometime at least.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...