I came across this conditional in a function I’m working with:
<?php
$thisweek = date('W');
if ($thisweek == 0) {
// ...
}
I didn’t write this conditional and when I went to look up the range of the date(‘W’) https://www.php.net/manual/en/function.date.php it gives an example but no range like 00-52 or 01-52.
My question is will date(‘W’) ever return zero meeting this conditional?
The PHP
date('W')function will never1 return 0.Look it up in the source code of PHP, ext/date/php_date.c.
Slightly formatted around line 950-1000:
What is timelib_isoweek_from_date? Well… looking at the logic in ext/date/lib/dow.c, from line 82 it can be concluded that the week number varies from 1 to 53:
If you do not believe me, look in the code yourself:
1) “Never” means “as long as there is no bug in PHP”.