Skip to content

Commit 4b17ba0

Browse files
rodrigoprimojrfnl
andcommitted
Simplify PHP type cast documentation
- Remove reference to deprecated (real) cast and PHP version-specific deprecation details. - Update code example to show correct/incorrect usage with (bool) and (boolean). Fixes 154. Co-authored-by: Juliette <[email protected]>
1 parent 59b2aa1 commit 4b17ba0

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)