Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124148 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id A03AC1A009C for ; Mon, 1 Jul 2024 16:40:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719852123; bh=uFr37OmNBg7z9hj3Douhes3HiHdegnORtSbbFG5yPos=; h=In-Reply-To:References:Date:From:To:Subject:From; b=fOexttzyjeUgXMrybFXmHszRHvUTSxhPA1eYIIqnw/S6fFDhL++Vwh56dSgfQJ8Zd xFSFfWuCNiS3F3to0DuAuE/cYHBGZiPcxDGL0HV4XsXNcDPLXM7CwMjh/izx1dF2PE jUgo1T67R9M12cKbEMw/EMd1NFrQkOEoB1A2Q1pR2VFxvgd930UiCMgrNVcLL9I5bw SAbr38qoZUeI1Jps/KfMe3eG9+B7eVk53U4/t8K55zDX+ka4hBPGjd/XmjJnsWqMVF 3+AnjH7ukaAGW4BQC8BH06Eb8Hyu+AvWc/2WzP8t6NosHgUc5NjZszigZAqpqSSbkq FZGdYL7mnI9Wg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 22E6E1806B4 for ; Mon, 1 Jul 2024 16:42:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from wfhigh1-smtp.messagingengine.com (wfhigh1-smtp.messagingengine.com [64.147.123.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 1 Jul 2024 16:42:02 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id E8A9718000C6 for ; Mon, 1 Jul 2024 12:40:40 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 01 Jul 2024 12:40:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:content-type:date:date:from :from:in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm2; t=1719852040; x= 1719938440; bh=EqlksIIaEYneL/WEcyetG9Uzvk2evuV5PQnmuoa2lBI=; b=W lgf/O61ZePEJDqTHVu8nlqlqlkO6PHTQtZ17FSdQvBastSAyxhTABcB6CFm9E2dC QkSpXpU2T9zG9AtBA1DUTSUsraelmHwYKUX5JVT64MCrdqQHpPUjDB4mfyhh1n30 Z8BTAyTjjJsFLWbEPI1n39S350MdGrnWbbRe/Md9hivEhzK5wq+pHkER2WhFhjbo wV61rK0WQzMM7mSLpsO9f8lv0Od4uYBBJJzrS6Z0OUfuNLT1+USspYgeQrlJ9fVc pQb9YFn6ioQoqXJQYMSVLv6egmoYjzL64gEEBl9qKLHKfx578SmFhjc5owcOIa3u SX4+YTzW8lF5iGXNOoyeg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719852040; x=1719938440; bh=EqlksIIaEYneL/WEcyetG9Uzvk2e vuV5PQnmuoa2lBI=; b=S/APEACQGRKJq9TJGJ1YcoIOrEVWWDbXQyfTXII69z2a dIM8yEoTCbo7FYI0KlW2XiiB2A9QhjJbc/R2D8VhndY5NLHoEU93mhMhnKFH1KPV vs9IXDxfsQhEINwmKZcpcp3Ni4l9UnSHx7hwZ2jrp1g/RjdNK9qY/uDUxInhEip8 N8U2H5/wB3bDaMCPFZ1rx8zp7MuisXiWbNZLhYSwq8KHEt3e7/2VBTGFC2zabbUg q+vGYGibZkb0wibfe/2p9TrjzDF8MYYravCdxrNsg5UhierGVk9BXFBvyAaaQp8W Rm4/uzax2NG4My5XlkJkEeUUQgri3nP/AYB9uy3L6g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgddutdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeevheehvdevjeelvdevgfelvefftdejkeelvdekgeeh fffgiedvjefhhfeltdduteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhi vghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id EE2BE1700093; Mon, 1 Jul 2024 12:40:39 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: References: Date: Mon, 01 Jul 2024 16:40:19 +0000 To: "php internals" Subject: Re: [PHP-DEV] Re: [Discussion] Add date_test_set_now() function Content-Type: text/plain From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jul 1, 2024, at 3:56 PM, Go Kudo wrote: > I apologize, the main point of my explanation was off. > > To put it simply, I'm suggesting that it might be good to implement > convenient and commonly used features from Carbon at the ext-date level. > > I'm proposing the date_test_set_now() function for the following reasons: > > User-land libraries like Carbon / Chronos have a setTestNow method, > indicating a potential demand for this feature. > It's impossible to determine whether a value is relative or absolute > time from either user-land or Extension. > While this is convenient for maintaining legacy systems, that's not the > essence of this proposal. > > As you pointed out, this is an issue that should ideally be solved in > user-land. I deeply understand that. > > However, in reality, PHP's time-related processing is diverse, and to > comprehensively handle all of these, it seems necessary to address this > at the ext-date level. > > https://www.php.net/manual/en/ref.datetime.php > > For example, you might want to use the date() function to display the > current time on a whim. However, doing this ruins everything. > > Even if other parts of your code use Carbon or comply with PSR-20, > using the date() function is problematic because the current time it > references cannot be modified. > > `date_test_now(\DateInterval $shiftInterval)` can solve this problem. > > Of course, there might be various side effects. However, seeing > `Carbon::setTestNow()` being used in various places, I think this > feature might be necessary. > > I would appreciate your thoughts on this. > > Best Regards, > Go Kudo They are unchanged. > For example, you might want to use the date() function to display the > current time on a whim. So don't do that. Relying on global mutable state is a bug. That older parts of the stdlib made that mistake doesn't mean we should continue it. (See also the Random extension, which also works to avoid global mutable state.) > Of course, there might be various side effects. Exactly. This is not something to just brush aside with a comment. The way Carbon does it is wrong, for the same reason: It just sets a global state. The correct answer is to use PSR-20 and inject a fixed-time instance of the Clock. --Larry Garfield