Open nielsdos opened 1 year ago
Well, yes, the name is a bit of a misnomer: it doesn't literally "set the type of the variable" (which isn't even a thing in this language) but, like the code says, instead does:
// settype($var, $type)
$ptr = $var;
"convert_to_$type"($var);
$var = $ptr;
Which explains why it works with typed properties.
Yeah I understand why it works, it just needs better documentation (i.e. the exception, and the coercion) to reduce the "huh?" factor :-)
The following code:
Resulted in this output:
But I expected this output instead:
Well either
bool(false)
or a type error, as its supposed to return false when setting the type fails according to the documentation. Although that's probably inaccurate, as the following code:Results in:
Fatal error: Uncaught TypeError: Cannot assign null to reference held by property Foo::$value of type int
. And the code forsettype
can only return true as far as I can see.So there's two documentation issues:
ext/standard/tests/general_functions/settype_typed_property.phpt
, but I didn't know this at first, until I tried fixing the behaviour I thought was a bug).