hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

Add <<__DoNotCallTwice>> attribute or similar

Open fredemmott opened this issue 9 years ago • 2 comments

eg shortcut for this pattern:

  static $called = false;
  invariant($called === false, __FUNCTION__.' should not be called twice');
  $called = true;

fredemmott avatar May 20 '15 18:05 fredemmott

I'm not convinced that this is a common enough pattern to be worth the effort? Could be wrong though. Also while the runtime semantics are clear, I'm not totally sure if the typechecker could enforce it, or how.

jwatzman avatar May 21 '15 11:05 jwatzman

How would this interact with coeffects? Would methods with this attribute require write_props? Would functions require write_globals?

I'd be surprised if a pure function would throw if the inputs were unchanging between one invocation to the next.

lexidor avatar Oct 04 '23 23:10 lexidor