Covariance: In PHP, the return type of method which belongs to the child can be more specific compared to the return type of method of parent. This is done through covariance. For example, consider the parent class “Bank”, and “SB” and “BOI” to be its children.
Arshit has an SBI account Simon has a BOI account
Contravariance: In PHP, the parameters of the method which belong to the child can be less specific compared to the parameters of the method of parent. This is done through contravariance.
Shreyank has account_no Shrey has an SBI account_detail
Note: By excluding type limitings on parameters of the child method, partial contravariance was achieved in PHP version 7.2.0. and in PHP version 7.4.0, complete contravariance and covariance were achieved. All older versions before version 7.2.0 will show error.
- PHP 5 vs PHP 7
- PHP | Get PHP configuration information using phpinfo()
- PHP | php.ini File Configuration
- How to import config.php file in a PHP script ?
- How to select and upload multiple files with HTML and PHP, using HTTP POST?
- Difference and Similarities between PHP and C
- LAMP installation and important PHP configurations on Ubuntu
- PHP | echo and print
- PHP | (Include and Require)
- HTTP GET and POST Methods in PHP
- PHP | Date and Time
- PHP | strpos() and stripos() Functions
- PHP | Imploding and Exploding
- PHP | include_once() and require_once()
- PHP | Separate odd and even elements from array without using loop
- PHP | Sort array of strings in natural and standard orders
- PHP program to find the maximum and the minimum in array
- Difference between try-catch and if-else statements in PHP
- Create a web server and run PHP script on it using Raspberry Pi
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.