Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. function getName(final Context $context) {
  2.     final $name = $context->isFormal() ? "Rodrigues" : "David";
  3.  
  4.     // Note that "$name" is final.
  5.     // Now I cannot change the $name variable.
  6.     // { ... do something else }
  7.  
  8.     return $name;
  9. }
  10.  
  11. echo getName(new FormalContext());   // Print "Rodrigues"
  12. echo getName(new InformalContext()); // Print "David"
  13.  
  14. // Note that the "$name" is final, but it have two different values depending of the context.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement