YouTube-operational-API icon indicating copy to clipboard operation
YouTube-operational-API copied to clipboard

Use `===` instead of `==` to be more precise

Open Benjamin-Loison opened this issue 3 years ago • 2 comments

Is there any similar rule? Make sure not to break anything by doing so.

So should proceed to #24 first.

By the way what is the rule in PHP to choose between quotes ' and "? Cf https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax. As a result should change liveChats.php. This Stack Overflow answer answers it quite well. I should use " à la printf instead of concatenating variables with ..

grep -r '"' --exclude-dir=.git/

I guess var and !var mean respectively var != false and var != true, and not var !== false and var !== true (which aren't equivalent to var === true and var === false, cf file_get_contents return value and the commit associated to this issue).

As:

<?php

    $a = 'test';

    if(!$a) {
        echo 'one';
    }

    if($a != false) {
        echo 'two';
    }

    if($a) {
        echo 'three';
    }

?>

echos twothree, my guess was wrong and !$a is interpreted as $a !== false, while $a is interpreted as $a == true.

As boolean conditions can come up quite everywhere, I should proceed to full code review while thi king about this issue.

Benjamin-Loison avatar Oct 04 '22 19:10 Benjamin-Loison

Following vim command helps a lot:

:%s/old/new/gc

Benjamin-Loison avatar Jul 10 '23 19:07 Benjamin-Loison

Still have " in index.php while they should be '.

Benjamin-Loison avatar Feb 23 '24 15:02 Benjamin-Loison