Apply patch from Bug#56904 because it can't hurt.

Also add test case for the observed behavior.
Add overloading for direct assignment.

class Foo {
  public $val;

  public function __assign($val) {
    $this->val = $val;
  }
}

$f = new Foo;
$f = 123;
var_dump($f->val); // int(123)