note 77951 added to language.oop5.interfaces
| From: | HayleyWatson at osu1 dot php dot net | Date: | Fri, 21 Sep 2007 05:35:08 +0000 |
| Subject: | note 77951 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130650@lists.php.net to get a copy of this message | ||
On an incidental note, it is not necessary for the implementation of an interface method to use the
same variable names for its parameters that were used in the interface declaration.
More significantly, your interface method declarations can include default argument values. If you
do, you must specify their implementations with default arguments, too. Just like the parameter
names, the default argument values do not need to be the same. In fact, there doesn't seem to
be any functionality to the one in the interface declaration at all beyond the fact that it is
there.
<?php
interface isStuffed {
public function getStuff($something=17);
}
class oof implements isStuffed {
public function getStuff($a=42) {
return $a;
}
}
$oof = new oof;
echo $oof->getStuff();
?>
Implementations that try to declare the method as getStuff(), getStuff($a), or getStuff($a,$b) will
all trigger a fatal error.
----
Server IP: 203.89.181.186
Probable Submitter: 60.234.168.92
----
Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/77951
Del: integrated -- https://master.php.net/note/delete/77951/integrated
Del: useless -- https://master.php.net/note/delete/77951/useless
Del: bad code -- https://master.php.net/note/delete/77951/bad+code
Del: spam -- https://master.php.net/note/delete/77951/spam
Del: non-english -- https://master.php.net/note/delete/77951/non-english
Del: in docs -- https://master.php.net/note/delete/77951/in+docs
Del: other reasons-- https://master.php.net/note/delete/77951
Reject -- https://master.php.net/note/reject/77951
Search -- https://master.php.net/manage/user-notes.php