Can you overload constructor in php




















I'm Amit. I write articles about all things web development. If you like what I write and want me to continue doing the same, I would like you buy me some coffees. I'd highly appreciate that. Get the latest articles delivered right to your inbox! Read a sample. First-class callables in PHP 8.

Please use ide. Load Comments. What's New. Most popular in PHP. How to convert array to string in PHP? Why to check both isset and! More related articles in PHP. BenV BenV 9 9 silver badges 16 16 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. The latter is deprecated, and can cause problems in name resolution when working with PHP 5. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

As unfortunate as this is, it is possible to devise a simple workaround, due to the fact that a method can be written to take an arbitrary number of parameters. It might not be pretty, but using this method you will be able to call the constructor of Foo as if it were actually overloaded:.

An alternative to this would be to use default parameters to determine what action to perform, but this method gets increasingly clumsy as the number of arguments grows.

You are commenting using your WordPress. You are commenting using your Google account. You are commenting using your Twitter account. You are commenting using your Facebook account. Notify me of new comments via email.



0コメント

  • 1000 / 1000