Difference between revisions of "PHP/interface"
< PHP
		
		
		
		Jump to navigation
		Jump to search
		 (Created page with "==About== In PHP, an '''interface''' is a set of public method-functions which can be required in either of two circumstances: * in the declaration of a class ** This work...")  | 
				|||
| Line 7: | Line 7: | ||
*** narrows down (more closely specifies) the function's expectations of a passed or returned object  | *** narrows down (more closely specifies) the function's expectations of a passed or returned object  | ||
*** does not tie the object to a specific class hierarchy  | *** does not tie the object to a specific class hierarchy  | ||
| − | ==  | + | ==Predefined==  | 
| − | * [https://www.php.net/manual/en/  | + | * {{l/sub|instanceof}} works with both classes and interfaces  | 
| + | ** [https://www.php.net/manual/en/language.operators.type.php official]  | ||
| + | * {{l/sub|interface_exists()}} returns TRUE if the interface has been declared in code that has executed.  | ||
| + | ** [https://www.php.net/manual/en/function.interface-exists.php official]  | ||
==Links==  | ==Links==  | ||
* official: [https://www.php.net/manual/en/language.oop5.interfaces.php interfaces]  | * official: [https://www.php.net/manual/en/language.oop5.interfaces.php interfaces]  | ||
| + | * '''2018-01-13''' [https://daylerees.com/php-interfaces-explained/ PHP Interfaces Explained]  | ||
Revision as of 01:08, 13 January 2020
About
In PHP, an interface is a set of public method-functions which can be required in either of two circumstances:
- in the declaration of a class
- This works almost identically to declaring the interface's methods as abstract functions in a trait or parent class.
 
 - the type of a function argument or return value
- Advantages over declaring the object as a class:
- narrows down (more closely specifies) the function's expectations of a passed or returned object
 - does not tie the object to a specific class hierarchy
 
 
 - Advantages over declaring the object as a class:
 
Predefined
- instanceof works with both classes and interfaces
 - interface_exists() returns TRUE if the interface has been declared in code that has executed.
 
Links
- official: interfaces
 - 2018-01-13 PHP Interfaces Explained