Page MenuHomePhabricator

Add linter rule to prevent exceptions from being thrown in a __toString method
Closed, ResolvedPublic

Description

The following code is invalid:

<?php

class MyClass {
  public function __toString() {
    throw new Exception('oops');
  }
}

Attempting to run will code will result in a fatal error:

PHP Fatal error:  Method MyClass::__toString() must not throw an exception

We should be able to detect this with a linter rule.