note 114305 deleted from language.oop5.interfaces by sobak
| From: | sobak@php.net | Date: | Thu, 01 Dec 2016 17:26:24 +0000 |
| Subject: | note 114305 deleted from language.oop5.interfaces by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207886@lists.php.net to get a copy of this message | ||
Note Submitter: phpnet at barrystaes dot nl
----
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.