Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123714 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 1D7861A009C for ; Thu, 20 Jun 2024 21:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1718919632; bh=VhS0Jc/eM6WhYGM6COnVZLybwQh8A91K5aReN8sz+64=; h=Date:Subject:To:References:From:In-Reply-To:From; b=Mfot8J4SY6Dw702ik8p01xf7vrGU3cvHmst1qJiGW1cHI9To1PATsdqr07iAfWUhD 4Z0S4u3BrmkpHMlgilDs1QLbhE/CZzI6yuQEBS7ms6Fjihtx4z2sxcwjrkTUOpTVZT 4bRWWYYiBPUL880WnhMlYfUPgpxNHwSw6dGYK92p04PPYN0PJrqpt2x/7ixpbGRIgR F/jc9rRakcR2ka4NKdKeERAf7b+SkeDKTs0OJI0x2opg2102GTkeYhLAaAsjuSgL0w XbFAiW/vQfEj3LGnducWv/mNzY+1kb3RHoeEwP5KaLi9yKBktL1C2mL9wgPyn9Jz/m Ce5XOCVVGuSDw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CBC501804D7 for ; Thu, 20 Jun 2024 21:40:31 +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,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,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 fhigh1-smtp.messagingengine.com (fhigh1-smtp.messagingengine.com [103.168.172.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 ; Thu, 20 Jun 2024 21:40:31 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 92EDB114014B for ; Thu, 20 Jun 2024 17:39:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 20 Jun 2024 17:39:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; 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=1718919556; x=1719005956; bh=5IGzvV0q14 1P2CFbFcXHrmsoQoG6ANLsacmo2wXnWws=; b=ZxSMkFNSblKQ/M+a1GH0zsEUKq CYmi/Us8+4aDQHMKu04plgz2aJJy9N7si/O78sUu9F7XYPeoqsjUMr3KHZuKkbJy mq4P3EkN1ChpgZCkmLNRrdBoXJ1VEWPx0sqN6mRgYfAFtrcbVxypRJR3U+wF2VXm I8C5Fv/UnCmC/u/E0yVwRQyInK9mWu4AjgJibn19AhoE15qT4D2YrmraLyBb+T11 mEvfqFZZcNcHiO15CzOi1kmcpQAlGVkxOjk2h/tdge2shA+hoIWjkUoS1bJkRGyl oBqUN9NGb1yRGP8heg18ThhH1cEjkcq9KjCw20GlGz2Y8txXhDV0RhJrJ9/A== 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=1718919556; x=1719005956; bh=5IGzvV0q141P2CFbFcXHrmsoQoG6 ANLsacmo2wXnWws=; b=TIFECeewXHgQgtQQzlCX6kKmaB1OnL+80VBCWD3x2llb imcMy9zLd27qhyRXU2I2I7jiWbqwYqL2pSf9prEdogyAB6EMIUV1YS7F/6ympGbX R3RvmZ4vGApzO41En2JUvwiwDv7qNuycb0XtpoYASvHie04f7Vvnh+Ly7Vo3y/w9 N4EsKHI1yl8WGIUDLLlAWLV/wgpHM0uB6UagpMz5umaEza//x/CyoSmEDoLUyk8m qIzgQSXiYV3T9KlYiN3xb30KoanJsMKuF+XLzm6HSMcAy/01JoBHVYCIidlHrnY8 EH5PcdJNTTCj4KRnIojQ1XdvaqsVj2zvEGYqAnX4ig== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrfeeffedgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpegtkfffgggfuffvfhfhjgesrgdtre ertddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcu oehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhephe etleeiiefgueduieeuieffvdevheduueefkeejuefgffeftdeitdegtedtleetnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrph hhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 20 Jun 2024 17:39:15 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------Ur3Bhj5bKToxOOshV8tyHBc1" Message-ID: <350c1531-9bcf-4e7c-824b-8d9904b9e48e@rwec.co.uk> Date: Thu, 20 Jun 2024 22:39:11 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] Renaming "strict types" to "scalar type coercion" To: internals@lists.php.net References: <9d28c9tOCChpWUcP1SFiFwtf2-w2XAtDzHsmM73myA7zfBsn7TxxEqs-VCnxRAgZjsk2TxS55owmM8wSLgBQL8LgeQLntUQ9toeLMkjTVx4=@gpb.moe> <673a1803-83c4-44b4-bd73-4ba61e83412e@app.fastmail.com> Content-Language: en-GB In-Reply-To: <673a1803-83c4-44b4-bd73-4ba61e83412e@app.fastmail.com> From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------Ur3Bhj5bKToxOOshV8tyHBc1 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 19/06/2024 16:34, Larry Garfield wrote: > Also, as someone who does put every file into strict mode as a matter of > course, and appreciates the many languages that do not even have a > concept of non-strict mode (like Go or Rust), I really don't appreciate > the backhanded comments in this thread about people who, you know, care > about type safety. (Something that weak mode, when it was introduced in > PHP 7, only marginally provided if at all.) Strict mode prevents bugs, > full stop, and we should not fault anyone for applying that bug-stopper > tool liberally. Used correctly, it absolutely does. Used incorrectly, it can actually end up *hiding* errors. I've seen lots of cases where code like this: some_function_expecting_int($_GET['foo']); Gets changed to this: declare(strict_types=1); some_function_expecting_int( (int)$_GET['foo'] ); Even in PHP 7.0, the first version is actually *stricter* than the second, because explicit casts never fail, but parameter coercion (mode 0) always failed for strings like "hello"; as of 8.0, it also fails for strings like "123foo" and "". And this is exactly the kind of code that coercive type hints were intended for - HTTP is a text-based protocol, so most PHP applications are dealing with string input and output *all the time*. One of the things the language badly needs, and I have been trying to come up with a proposal for, is strict type casts, so that this code can actually be written safely but still concisely. Regards, -- Rowan Tommins [IMSoP] --------------Ur3Bhj5bKToxOOshV8tyHBc1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
On 19/06/2024 16:34, Larry Garfield wrote:
Also, as someone who does put every file into strict mode as a matter of
 course, and appreciates the many languages that do not even have a 
concept of non-strict mode (like Go or Rust), I really don't appreciate 
the backhanded comments in this thread about people who, you know, care 
about type safety.  (Something that weak mode, when it was introduced in
 PHP 7, only marginally provided if at all.)  Strict mode prevents bugs,
 full stop, and we should not fault anyone for applying that bug-stopper
 tool liberally.


Used correctly, it absolutely does. Used incorrectly, it can actually end up *hiding* errors.

I've seen lots of cases where code like this:

some_function_expecting_int($_GET['foo']);

Gets changed to this:

declare(strict_types=1);
some_function_expecting_int( (int)$_GET['foo'] );

Even in PHP 7.0, the first version is actually *stricter* than the second, because explicit casts never fail, but parameter coercion (mode 0) always failed for strings like "hello"; as of 8.0, it also fails for strings like "123foo" and "".

And this is exactly the kind of code that coercive type hints were intended for - HTTP is a text-based protocol, so most PHP applications are dealing with string input and output *all the time*.

One of the things the language badly needs, and I have been trying to come up with a proposal for, is strict type casts, so that this code can actually be written safely but still concisely.


Regards,

-- 
Rowan Tommins
[IMSoP]
--------------Ur3Bhj5bKToxOOshV8tyHBc1--