Jump to content
Larry Ullman's Book Forums

Recommended Posts

According to the book when overriding a parent class must use the same number of parameters. Why is this? What happens when I pass one more parameter. I tested it by passing an extra parameter than the original (parent) signature and it works just fine so I failed to understand the idea behind having the same number of parameters. Can someone clarify this?

 

Thanks

Share this post


Link to post
Share on other sites

Sorry for the confusion. In other OOP languages, you can create multiple methods with the same name but a different number of parameters. The parent version of the method might take 2 parameters but the child version would take 3. Which version of the method is called will depend upon how many parameters are passed. This is known as overloading a method. PHP does not support the traditional version of overloading is the main point of what I'm trying to say. I believe PHP will throw an error if you intend to override a method but you actually overload it. 

 

I expect what you witnessed when passing extra arguments (which is different than defining it to accept a different number of parameters) is that PHP ignore the extra argument because there's no parameter for it.

Share this post


Link to post
Share on other sites
Guest Deleted

This helps me. I was confused on what overloading was all about. Overriding made perfect sense, overloading did not.

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...