hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

nums should be Stringish

Open HRMsimon opened this issue 10 years ago • 3 comments

HHVM Version

3.15.0

Standalone code, or other way to reproduce the problem

<?hh

$value = 7;
echo <input type="number" value={$value} />;

Expected result

<input type="number" value="7" />

Actual result

 attribute `value` of type `integer` supplied to element `input`, expected `Stringish`.

This particular example throws a Hack error, but it's just a simplified version of what we ran into. Not having num be of type Stringish is rather annoying for this particular case (value of a number input) as it requires wrapping the variable in a string, which Hack doesn't like.

The way I see the Stringish type is that it represents a value that can be safely casted to a string. A num certainly fulfils that condition.

HRMsimon avatar Sep 12 '16 23:09 HRMsimon

cc @fredemmott as we've only had this issue while using XHP and their might be something that can be done there to work around this.

HRMsimon avatar Sep 12 '16 23:09 HRMsimon

XHP won't be special-casing this; consistency with Hack's type system is a goal of 2.x+.

fredemmott avatar Sep 13 '16 14:09 fredemmott

I am going over old issues on this repository, to see which ones apply to the current versions of hhvm.

Although Stringish hasn't been ouright removed yet. The hhvm team has been trying to get rid of it since hhvm 3.30.0, but this has taken quite a bit longer than expected.

  • 3.30.0 Casting objects to strings will no longer be supported (hhvm.fatal_on_convert_object_to_string); this includes removal of support for __toString().
  • 4.19.0 The Stringish interface is deprecated, and can not be converted to a string without a typechecker error.
  • 4.44 string casts of Stringish objects will change to raise a runtime exception; the hhvm.notice_on_implicit_invoke_to_string option can be used to detect this.
  • 4.52 Runtime support for casting objects to strings via __toString will be removed shortly; this includes (string) $obj, print($obj), sprintf('%s', $obj) among others. The hhvm.notice_on_implicit_invoke_to_string INI setting can be used to find calls that will break.

The only changes being made to Stringish are those that aid in its removal.

lexidor avatar May 26 '20 23:05 lexidor