note 47759 added to language.oop5.interfaces
| From: | russ dot collier at gmail dot com | Date: | Sun, 28 Nov 2004 18:24:55 +0000 |
| Subject: | note 47759 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81126@lists.php.net to get a copy of this message | ||
You can also specify class constants in interfaces as well (similar to specifying 'public
static final' fields in Java interfaces):
<?php
interface FooBar
{
const SOME_CONSTANT = 'I am an interface constant';
public function doStuff();
}
?>
Then you can access the constant by referring to the interface name, or an implementing class,
(again similar to Java) e.g.:
<?php
class Baz implements FooBar
{
//....
}
print Baz::SOME_CONSTANT;
print FooBar::SOME_CONSTANT;
?>
Both of the last print statements will output the same thing: the value of FooBar::SOME_CONSTANT
----
Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47759
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47759&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47759&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47759&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47759&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47759&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47759&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47759&report=yes
Search -- http://master.php.net/manage/user-notes.php