Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange phrasing in bool conversion section #1334

Open
williewillus opened this issue Mar 10, 2023 · 1 comment
Open

Strange phrasing in bool conversion section #1334

williewillus opened this issue Mar 10, 2023 · 1 comment

Comments

@williewillus
Copy link

In the section on boolean conversions:
https://docs.hhvm.com/hack/types/type-conversion#conversion-to-bool

The first sentence says "No non-bool type can be converted implicitly to bool. All other conversions must be explicit.".

But then the proceeds proceeds to give a long list of implicit conversions.

@lexidor
Copy link
Contributor

lexidor commented Mar 27, 2023

Hi, leaving a drive-by comment here.

I do agree that the sentence structure is strange. It reads: No non-x can be implicitly converted to x. which is equivalent to: No value can be implicitly converted to a value of type x.

The sentence All other conversions to type x must be explicit. could then be written as: Converting a value to a value of type x must be done explicitly.

The comment about needing an explicit conversion is correct though. function takes_bool(bool $b): void; can not be called with an int without an explicit conversion. takes_bool((bool) 0) or takes_bool(boolval(0)).

Implicit conversion from classname to string is an example where no explicit conversion is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants