note 95254 added to overload.examples.basic
| From: | author at dereleased dot com | Date: | Mon, 21 Dec 2009 20:30:06 +0000 |
| Subject: | note 95254 added to overload.examples.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-164245@lists.php.net to get a copy of this message | ||
While the term "overloading" in many other languages specifically means declaring multiple
methods with the same name and having the compiler intelligently select which one should be run at
any given time, this (as some have pointed out) is not the case in PHP, for a very simple yet
important reason:
PHP is a weakly/dynamically typed language; the only exceptions to this rule are constants (which
have certain type restrictions, e.g. array) and Type-Hinted method arguments. Because of this,
traditional overloading style is simply not possible, as there is no way for the interpreter to know
which method to call (reliably).
However, with PHP's ability to accept an indefinite number of undefined arguments via
func_get_args() and related functions, as well as simply provide defaults to values to allow you to
declare just one method and perform simple tests to see if some/all of the arguments were indeed
passed, traditional means of method overloading are not entirely necessary.
It may not be what you're used to, but it works.
----
Server IP: 64.71.164.2
Probable Submitter: 209.155.240.195
----
Manual Page -- http://www.php.net/manual/en/overload.examples.basic.php
Edit -- https://master.php.net/note/edit/95254
Del: integrated -- https://master.php.net/note/delete/95254/integrated
Del: useless -- https://master.php.net/note/delete/95254/useless
Del: bad code -- https://master.php.net/note/delete/95254/bad+code
Del: spam -- https://master.php.net/note/delete/95254/spam
Del: non-english -- https://master.php.net/note/delete/95254/non-english
Del: in docs -- https://master.php.net/note/delete/95254/in+docs
Del: other reasons-- https://master.php.net/note/delete/95254
Reject -- https://master.php.net/note/reject/95254
Search -- https://master.php.net/manage/user-notes.php