Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getName(final Context $context) {
- final $name = $context->isFormal() ? "Rodrigues" : "David";
- // Note that "$name" is final.
- // Now I cannot change the $name variable.
- // { ... do something else }
- return $name;
- }
- echo getName(new FormalContext()); // Print "Rodrigues"
- echo getName(new InformalContext()); // Print "David"
- // 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