craigk5n / webcalendar

WebCalendar is a PHP application used to maintain a calendar for a single user or an intranet group of users. It can also be configured as an event calendar.
http://www.k5n.us/webcalendar.php
GNU General Public License v2.0
148 stars 70 forks source link

example of converting ==|!= to ===|!== #413

Open bbannon opened 9 months ago

bbannon commented 9 months ago

why? because ! empty ( $x ) && $x == 'Y' can be shortened to $x === 'Y' without losing anything. as $x in $x === 'Y' can not be empty, null, undefined, not set, 'zebra' or anything else except 'Y'

Also, some examples of making changed lines comply with developers-guide as far as line length and spaces around ()s and such.

craigk5n commented 9 months ago

I don't think this actually correct as far as avoiding undefined vars.

I tried this script:

<?php
if ( $B === 1 ) {
  echo "B is 1\n";
}
?>

And got this result with PHP 8.2: PHP Warning: Undefined variable $B in /var/www/html/webcalendar/test.php on line 3

bbannon commented 9 months ago

What do you get for if ( $b !== 1 )

or

if ( $b === '1' )

On Tue, Sep 19, 2023 at 9:06 AM Craig Knudsen @.***> wrote:

I don't think this actually correct as far as avoiding undefined vars.

I tried this script:

<?php if ( $B === 1 ) { echo "B is 1\n"; } ?>

And got this result with PHP 8.2: PHP Warning: Undefined variable $B in /var/www/html/webcalendar/test.php on line 3

— Reply to this email directly, view it on GitHub https://github.com/craigk5n/webcalendar/pull/413#issuecomment-1725834550, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHJ7GLV7ZEX6YRHOXST7Q5DX3GYIPANCNFSM6AAAAAA42XNW7Q . You are receiving this because you authored the thread.Message ID: @.***>

craigk5n commented 9 months ago

What do you get for if ( $b !== 1 ) or if ( $b === '1' ) On Tue, Sep 19, 2023 at 9:06 AM Craig Knudsen @.> wrote: I don't think this actually correct as far as avoiding undefined vars. I tried this script: <?php if ( $B === 1 ) { echo "B is 1\n"; } ?> And got this result with PHP 8.2: PHP Warning: Undefined variable $B in /var/www/html/webcalendar/test.php on line 3 — Reply to this email directly, view it on GitHub <#413 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHJ7GLV7ZEX6YRHOXST7Q5DX3GYIPANCNFSM6AAAAAA42XNW7Q . You are receiving this because you authored the thread.Message ID: @.>

I got undefined variable for both of these cases.

bbannon commented 9 months ago

Well, that's annoying. All 3 work on my machine, and the documentation suggests it should work for everyone.

On Thu, Sep 21, 2023 at 9:10 PM Craig Knudsen @.***> wrote:

What do you get for if ( $b !== 1 ) or if ( $b === '1' ) … <#m-661119662859921926> On Tue, Sep 19, 2023 at 9:06 AM Craig Knudsen @.> wrote: I don't think this actually correct as far as avoiding undefined vars. I tried this script: And got this result with PHP 8.2: PHP Warning: Undefined variable $B in /var/www/html/webcalendar/test.php on line 3 — Reply to this email directly, view it on GitHub <#413 (comment) https://github.com/craigk5n/webcalendar/pull/413#issuecomment-1725834550>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHJ7GLV7ZEX6YRHOXST7Q5DX3GYIPANCNFSM6AAAAAA42XNW7Q https://github.com/notifications/unsubscribe-auth/AHJ7GLV7ZEX6YRHOXST7Q5DX3GYIPANCNFSM6AAAAAA42XNW7Q . You are receiving this because you authored the thread.Message ID: @.>

I got undefined variable for both of these cases.

— Reply to this email directly, view it on GitHub https://github.com/craigk5n/webcalendar/pull/413#issuecomment-1730742502, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHJ7GLRW6W36K646ZZPZIN3X3T6SDANCNFSM6AAAAAA42XNW7Q . You are receiving this because you authored the thread.Message ID: @.***>

bbannon commented 9 months ago

Well, even if some form of '! empty()' is still required, everything I've read says it's better to use === | !== anyway.