note 28956 deleted from language.oop by vincent
| From: | vincent@php.net | Date: | Thu, 11 Sep 2003 20:06:45 +0000 |
| Subject: | note 28956 deleted from language.oop by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56217@lists.php.net to get a copy of this message | ||
Note Submitter: Evil Liam
----
Warning!
PHP does not seem to mind if you declare methods (or even constructors) with the same name in a
class.
class Object {
function Object() {
echo "Created\n";
}
function Method() {
echo "First Method\n";
}
function Method() {
echo "Second Method\n";
}
}
$Instance=new Object();
$Instance->Method();
Output is:
Created
Second Method
Most of the time, it seems to just call the last method declared with that name. However, I have
seen it fail in unusual circumstances involving locally-scoped assert() statements and methods with
the same name as the constructor. Be on the safe side, and avoid redeclaring method or constructor
names.