Skip to content

Commit 588a2e1

Browse files
committed
more details about identical comparison
1 parent 348809d commit 588a2e1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,20 +397,28 @@ function createMicrobrewery(string $breweryName = 'Hipster Brew Co.'): void
397397
**Not good:**
398398

399399
```php
400-
if( $a == $b )
401-
{
402-
//...
400+
$a = '42';
401+
$b = 42;
402+
Use the simple comparison will convert the string in an int
403+
404+
if( $a != $b ) {
405+
//The expression will always passes
403406
}
407+
404408
```
409+
The comparison $a != $b return false but in fact it's true !
410+
The string '42' is different than the int 42
405411

406412
**Good:**
407-
413+
Use the identical comparison will compare type and value
408414
```php
409-
if( $a === $b )
410-
{
411-
//...
415+
if( $a !== $b ) {
416+
//The expression is verified
412417
}
418+
413419
```
420+
The comparison $a !== $b return true.
421+
414422
**[⬆ back to top](#table-of-contents)**
415423

416424

0 commit comments

Comments
 (0)