note 28956 added to language.oop
| From: | Evil at rack1 dot php dot net | Date: | Wed, 29 Jan 2003 05:00:41 +0000 |
| Subject: | note 28956 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43015@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/language.oop.php
http://master.php.net/manage/user-notes.php?action=edit+28956
http://master.php.net/manage/user-notes.php?action=delete+28956
http://master.php.net/manage/user-notes.php?action=reject+28956