note 114305 added to language.oop5.interfaces
| From: | phpnet at barrystaes dot nl | Date: | Wed, 05 Feb 2014 13:21:10 +0000 |
| Subject: | note 114305 added to language.oop5.interfaces | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198412@lists.php.net to get a copy of this message | ||
Despite my expectations, it seems PHP does not support variables of type interface!? (using PHP 5.5)
<?php
interface InterfaceText {
public function setText($text);
}
class Sticker implements InterfaceText {
public function setText($text);
}
// While this is possible:
$Cool = new Sticker ();
// You can not make interface variables.
$IntfCool = new InterfaceText($Cool);
// ^ Fatal error: Cannot instantiate interface InterfaceText()
// or cast them directly:
$IntfCool = InterfaceText($Cool);
// ^ Fatal error: Call to undefined function InterfaceText()
?>
Being used to what other languages allow Interfaces, it seems PHP has no runtime support, i now see
it a static class that generates parse-warnings to force implementation.
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.oop5.interfaces.php
Edit -- https://master.php.net/note/edit/114305
Del: integrated -- https://master.php.net/note/delete/114305/integrated
Del: useless -- https://master.php.net/note/delete/114305/useless
Del: bad code -- https://master.php.net/note/delete/114305/bad+code
Del: spam -- https://master.php.net/note/delete/114305/spam
Del: non-english -- https://master.php.net/note/delete/114305/non-english
Del: in docs -- https://master.php.net/note/delete/114305/in+docs
Del: other reasons-- https://master.php.net/note/delete/114305
Reject -- https://master.php.net/note/reject/114305
Search -- https://master.php.net/manage/user-notes.php