Skip to content

Commit 96d4aca

Browse files
authored
Merge pull request #155 from rodrigoprimo/update-type-casts-doc
Simplify PHP type cast documentation
2 parents 7dba59c + 4b17ba0 commit 96d4aca

File tree

1 file changed

+3
-4
lines changed
  • wordpress-coding-standards

1 file changed

+3
-4
lines changed

wordpress-coding-standards/php.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,11 @@ When performing logical comparisons, do it like so:
202202
if ( ! $foo ) { ...
203203
```
204204

205-
[Type casts](https://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting) must be lowercase. Always prefer the short form of type casts, `(int)` instead of `(integer)` and `(bool)` rather than `(boolean)`. For float casts use `(float)`, not `(real)` which is [deprecated](https://www.php.net/manual/en/migration74.deprecated.php#migration74.deprecated.core.real) in PHP 7.4, and removed in PHP 8:
205+
[Type casts](https://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting) must be lowercase. Always prefer the short, canonical form of type casts, `(int)` instead of `(integer)` and `(bool)` rather than `(boolean)`. For float casts use `(float)`.
206206

207207
```php
208-
foreach ( (array) $foo as $bar ) { ...
209-
210-
$foo = (bool) $bar;
208+
$foo = (bool) $bar; // Correct.
209+
$foo = (boolean) $bar; // Incorrect.
211210
```
212211

213212
When referring to array items, only include a space around the index if it is a variable, for example:

0 commit comments

Comments
 (0)