facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.18k stars 2.99k forks source link

Ban non-void return from __construct, __destruct, __clone? #3757

Open fredemmott opened 10 years ago

fredemmott commented 10 years ago

I've found one case of this in Facebook:

class Foo {
  public function __clone(): Foo {
    return new Foo( ... );
  }
}

This looks like a misunderstanding about how __clone works, as it's called after a copy, instead of to actually do the copy. See http://php.net/manual/en/language.oop5.cloning.php

t5158846 for fixing the issue in Facebook.

jwatzman commented 10 years ago

Pretty sure we already do this for __construct (since we special case that enormously), but seems useful for the others too.

lexidor commented 4 years ago

Not needed for __destruct(), since it is gone. Adding it to __clone() would be a major improvement.

lexidor commented 1 year ago

Tracked as hhvm/hhast#546