Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active December 22, 2015 01:28
Show Gist options
  • Select an option

  • Save wilmoore/6396227 to your computer and use it in GitHub Desktop.

Select an option

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.
<?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) {}
}
<?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