Last active
December 22, 2015 01:28
-
-
Save wilmoore/6396227 to your computer and use it in GitHub Desktop.
Such an arbitrary limitation -- this should be enough to convince you to switch to a language that has a sane level of expressiveness.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class WordProblem { | |
| /** | |
| * sorry, but this won't work | |
| */ | |
| private $BINARY_OPERATORS = [ | |
| 'plus' => function($l, $r) { return $l + $r; }, | |
| 'minus' => function($l, $r) { return $l - $r; }, | |
| 'multiplied by' => function($l, $r) { return $l * $r; }, | |
| 'divided by' => function($l, $r) { return $l / $r; } | |
| ]; | |
| public function __construct($question) {} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class WordProblem | |
| { | |
| private $BINARY_OPERATORS; | |
| public function __construct($question) { | |
| // you are forced to make the assignment here | |
| $this->BINARY_OPERATORS = [ | |
| 'plus' => function($l, $r) { return $l + $r; }, | |
| 'minus' => function($l, $r) { return $l - $r; }, | |
| 'multiplied by' => function($l, $r) { return $l * $r; }, | |
| 'divided by' => function($l, $r) { return $l / $r; } | |
| ]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment