xp-framework / compiler

Compiles future PHP to today's PHP.
19 stars 0 forks source link

Implement throw expressions #53

Closed thekid closed 6 years ago

thekid commented 6 years ago

As suggested in #51:

Inside null-coalescing operator (??)

return $user ?? throw new IllegalStateException('No such user');

Inside ternary operator (?:)

return $user ?: throw new IllegalStateException('No such user');
return $args ? $args[0] : throw new IllegalStateException('At least one argument expected');

Inside arrow functions

$raise= $message ==> throw new IllegalStateException($message);
$raise('No such user');

Inside compact functions and methods

class Test {
  public function setup() ==> throw new MethodNotImplementedException(__METHOD__);
}
thekid commented 4 years ago

TODO: Check compatibility with https://wiki.php.net/rfc/throw_expression