Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Limited return type covariance and argument type contravariance

207 views

Published on

Limited return type covariance and argument type contravariance

Published in: Software
  • Be the first to comment

  • Be the first to like this

Limited return type covariance and argument type contravariance

  1. 1. Limited return type covariance and argument type contravariance
  2. 2.
  3. 3. 🎉🎉
  4. 4.
  5. 5. <?php class User {     public int $id;     public string $name; } ?>
  6. 6. <?php $factor = 10; $nums = array_map( fn($n) => $n * $factor, [1, 2, 3, 4] // function($n) use ($factor){ // return $n * $factor; // } ,[1, 2, 3, 4] ); // $nums = array(10, 20, 30, 40); ?>
  7. 7. <?php $parts = ['apple', 'pear']; $fruits = ['banana', 'orange', ...$parts ,
 ‘watermelon']; // ['banana', 'orange', 'apple', 'pear', 'watermelo n']; ?>
  8. 8. Limited return type covariance and argument type contravariance
  9. 9. 
 🎉🎉
  10. 10.
  11. 11. 🎉🎉
  12. 12. 
 <?php class A {} class B extends A {} class Producer {     public function method(): A {} } class ChildProducer extends Producer {     public function method(): B {} } ?>
  13. 13. 
 
 
 

  14. 14. 
 
 <?php class A {} class B extends A {} class Producer(B $b) {     public function method(): A {} } class ChildProducer(A $a) extends Producer {     public function method(): B {} } ?>
  15. 15.
  16. 16. 
 
 
 

  17. 17. 
 
 
 
 

  18. 18. 😚
  19. 19. 👿

×