php / php/php-src

strtotime() has strange interpretation of decimal weeks

オープン
#21,027 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

@derickr がすでに取り組んでいます。

2026年1月24日 から。

Extension: date Feature Status: Requires RFC
主要言語
C
スター
40.4k
フォーク
8.1k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

The following code:

<?php
strtotime("2.37685 weeks");

Resulted in this output:

1613443020

The code interpreted 2.37685 weeks as 02:37 (hours) and 685 weeks. This is non logical input of course (and not GNU compliant). But this isn't a very logical interpretation of this value from a human perspective and can easily be used incorrectly by users of the code without noticing.

The parser decided to not be able to recognize weeks, then fallback to hours, interpret up to 2 decimals (compliant with hour parsing), then split the remainder and continue parsing, interpreting the rest as the input for weeks.

This has been a known (usability) issue since 2007, when it was first encountered by Wikipedia, but an upstream ticket was never filed until now.

I consider this a usability pitfall of this function, that in my opinion should be rectified

  • it is illogical that a decimal is cutoff at 2 places
  • the cutoff value is assigned an implicit unit
  • the remainder of the value is suddenly a NEW secondary input
  • it adds both of them to form something way bigger than the user had expected

I suggest that if a decimal is recognized and unit is weeks, that this function throws a warning (recognize but don't accept)

PHP Version
PHP 8.4.16 (cli) (built: Dec 16 2025 16:03:34) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.4.16, Copyright (c) Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans
    with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies
Operating System

macos

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。