Saturday, 10 April 2021

php is loosely coupled: === operator

php is loosely written.

 

Example

"123" == 123 returns true. to avoid these kind of problems always use === (strict comparison operator) operator which checks for data type too.

 

strict_comparison_operator.php

#!/usr/bin/php

<?php
if ("123" == 123) {
    echo "\"123\" and 123 are equal using == operator";
}

if ("123" === 123) {
    echo "\"123\" and 123 are equal using === operator";
}

?>

 

Output

$./strict_comparison_operator.php 

"123" and 123 are equal using == operator

 

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment