3v4l.org

run code in 300+ PHP versions simultaneously
<?php const WEEK_YEAR_FORMAT = 'o-W'; function subtract_weeks_from_iso_week( string $start, int $weeks ): string { // Inputs are guaranteed (per usage) to be in 'o-W' => 'YYYY-WW' format. [ $start_year, $start_week ] = array_map( 'intval', explode( '-', $start ) ); $start_date = ( new DateTimeImmutable() )->setISODate( $start_year, $start_week ); $result_date = $start_date->modify( '-' . $weeks . ' weeks' ); return $result_date->format( WEEK_YEAR_FORMAT ); } echo subtract_weeks_from_iso_week(null, 4);
Output for 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught TypeError: subtract_weeks_from_iso_week(): Argument #1 ($start) must be of type string, null given, called in /in/cJMtn on line 12 and defined in /in/cJMtn:4 Stack trace: #0 /in/cJMtn(12): subtract_weeks_from_iso_week(NULL, 4) #1 {main} thrown in /in/cJMtn on line 4
Process exited with code 255.

preferences:
55.74 ms | 406 KiB | 5 Q