note 101723 added to language.oop5.interfaces
| From: | jballard at natoga dot com | Date: | Thu, 06 Jan 2011 21:33:30 +0000 |
| Subject: | note 101723 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-175505@lists.php.net to get a copy of this message | ||
If it isn't already obvious, you can create an object of a class above the class declaration if
it does NOT implement an interface. However, when a class DOES implement an interface, PHP will
throw a "class not found" error unless the instantiation declaration is _below_ the class
definition.
<?php
$bar = new foo(); // Valid
class foo
{
}
?>
<?php
$bar = new foo(); // Invalid - throws fatal error
interface foo2
{
}
class bar implements foo2
{
}
$bar = new foo(); // Valid, since it is below the class declaration
?>
Also, @Jeffrey -- Lol? What? Is that a joke? PHP interfaces have nothing to do with connecting to
"peripheral devices" or "cameras", etc. Not even in the least sense. This is a
very common miscommunication with the word "interface", as interfaces in programming are
not at all like interfaces in electronics or drivers, etc.
----
Server IP: 69.147.83.197
Probable Submitter: 70.56.151.147
----
Manual Page -- http://www.php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/101723
Del: integrated -- https://master.php.net/note/delete/101723/integrated
Del: useless -- https://master.php.net/note/delete/101723/useless
Del: bad code -- https://master.php.net/note/delete/101723/bad+code
Del: spam -- https://master.php.net/note/delete/101723/spam
Del: non-english -- https://master.php.net/note/delete/101723/non-english
Del: in docs -- https://master.php.net/note/delete/101723/in+docs
Del: other reasons-- https://master.php.net/note/delete/101723
Reject -- https://master.php.net/note/reject/101723
Search -- https://master.php.net/manage/user-notes.php