Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109505 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33858 invoked from network); 2 Apr 2020 11:26:52 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Apr 2020 11:26:52 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 86C0E1804D0 for ; Thu, 2 Apr 2020 02:53:28 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS8560 212.227.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 2 Apr 2020 02:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1585821205; bh=fIMnpbuHuqqtge/m7zaMaPxsbnppvPaMHRqK2G2cB54=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=f91ThhUShawrAYec6osK5peuBOcwhvMuNHoePFH0gaF/iacTQHZuIarznD8EHASxj l5Za8hpzSV12Q/Obz/ipHSUe174cMwTNVjciq/hMnAf0FETMg2XZAiusmhCrVHNYzp BTGFYZ4wH8MKAbxRBeQi+JG8kXFRuqhOyHiOEPJ0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.2.130] ([91.8.171.81]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N0oG5-1j5HSi1VUT-00wnlh; Thu, 02 Apr 2020 11:53:25 +0200 To: Nikita Popov Cc: PHP internals References: Message-ID: <499ec325-22cd-9cea-aaab-74c9810a9a34@gmx.de> Date: Thu, 2 Apr 2020 11:53:23 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ndoACW5/AZs+KXiRTnQ47+/xkAnEA/1sxUZy79Mx5t4zkREjFDh NRfVDPdFNOe3KXGizJIjJvBdBw7C4HYptnsxFV10CQaz4EDA6rXqQPsz2E7Osn+8rKe4gK5 SqkOPL66ZkxWTh9r9eB+f84v6CYgNeEGHa40ps2ipzPMWMxPyHmXUJzcz6fJPzmqzFEGepV FsweOhpAY+BcNS7qc3YCA== X-UI-Out-Filterresults: notjunk:1;V03:K0:FmFZkIBD6wc=:WOJFCyjiEzAlZux+c3tlKG abrsALM+n8xok2exse+Q9mvJ0LsTUXKfke9yDAUIbMceGDzrgfZvFO+c3TMdzBX+E6k6nyojh rR4bk2jEsLxy35JiKghwQmZxNF1J7y24+EVR1PS+ySjzfUc/ftPHerYeM0qKr+MdQo/8MbLPW WeIieXbLgu3CtEJFDxx8U1eOTumR05v1ugv7qwlYnzFzIQmbLm5cQaLAau/PAPC9PcBpvfUjj AmwPGaAElORebUmnQyhZSUOvmeWc2+Niwt4rN8EZ9Nzy9e4HCuo8V8RrLBzRivhvCGRAXvmXP UWgSKthnnnBrobXyH2WueNRMRJ552hyvWKKsbdU6JVxWBrKPXJaQw1wBdSMTgEqmyB0BUmZcW 147VKFEOlY/ajCQTa+gYFG3AntyTnti0YhrFTBJz/kb1jla5i52lCQQffPe0Qe6USxNRkcRt/ A/LVFcYrsLcY98b8pUix+oH9iqE21SUa46K7w36BfqaWWJXIKhYxKG67fhD86UtnjVmd8QOAK 07F8NwjL/J9AxShB4sa1Jybk/0R7bDFyIlfePrZermRBC9cMVfm74zaobTkpL6Zq1nhsEYl0V qqgaeh0MJ43UwEU+LHxH0Fqk2Us0hjANkP71po1IQUr+gRLRqBmtjtpnWfaPDatRVC2YzI6r5 SpsU10+zw8jn50yW9qnYsuusdGjoAT5nCPua/TNnWbCZy3U+j985nJ6za14uvPcB+pIDkWCnx lw/59sWp0mqOfhnrLrLiDokmQpPnc58oJpDu6Ox+UUhDz43dwYb/wOVM6eFlY5DY+AQAcJRQT NxFpAHMtQ7GQCOai5ozuOc7bnYwHFBsKLFkZ3fQZ8UNyBQznA4EGhbPkZNlrO2VnJJSdQPpEq AJbNm5gGrO8Yobo3LvKA5FPkomIqD/BzCp+Nu3dZDMQkZAUGCgPMAFNXToSPgMdhFm5W0Cmyn aOpf5yGEOdkv3RBxMurIHcVqEfSP0BgOLI9rFUkEVRBx88+GR+C8LtErFspT5oVq17TS+wlz7 IXgO9rjhmD/K++h2bnpE6DK7Lo+n5N/j4SlfHbaJSylRQqNHNCnXyULB2kWjR6tUsyLoY4NPJ va7hGFdJvSk6soljVtojQ6fyIqKCTxx3u1R+d0YULvZ+b+8Ci7cXeupRVv8y0HHj9NMKg7IbU VlWqD0gq5Vrr1uioJdvLjazg4lLLVsPysAoK1s77fjEhlERfbd8z/eHbUwDs3d7srDj8YdjTs ZjG48C2gGyr2cv2eD Subject: Re: [RFC] Stricter type-checks for arithmetic/bitwise operators From: cmbecker69@gmx.de ("Christoph M. Becker") On 02.04.2020 at 10:47, Nikita Popov wrote: > On Thu, Apr 2, 2020 at 10:35 AM Christoph M. Becker > wrote: > >> On 02.04.2020 at 10:14, Nikita Popov wrote: >> >>> I would like to propose making the use of arithmetic/bitwise operators= on >>> arrays, resources and (non-overloaded) objects a TypeError exception: >>> >>> https://wiki.php.net/rfc/arithmetic_operator_type_checks >> >> Thanks! Generally I like that very much. I'm not quite sure, though, >> what to do with resource to int conversions. These are documented to b= e >> valid[1], and are sometimes deliberately used[2], and as such it might >> be reasonable not to throw on these conversions (maybe even change the >> current behavior of the ~ operator). > > While resource to int conversions are indeed valid, they are not exactly > commonly used, and if they are used, I would expect an explicit (int) ca= st > to be involved. I very seriously doubt that someone writing "$x =3D $y /= 2" > really intended this to mean "$x =3D resource_id($y) / 2" -- it is much = more > likely that a variable go mixed up. In the unlikely case that that they > really did intend that, the option of writing "$resourceId =3D (int) $y;= $x =3D > $resourceId / 2" remains, and is much clearer. > > On that note, I do wonder whether we should introduce a function like > get_resource_id(), that makes it more explicit that an (int) cast is > supposed to fetch a resource ID. This is not a very common operation, an= d I > suspect that many PHP programmers may not be familiar with the semantics= of > integer casts on resources. Using get_resource_id($file) would make the > intent clearer relative to (int) $file. This is similar to the recently > added get_mangled_object_vars() function, which essentially does the sam= e > as (array) $object, but makes it obvious that you really are interested = in > mangled properties. I think something like get_resource_id() would be a good addition. >> After all, I hope we will be able >> to port all resources to objects sometime, and till then we could stick >> with more lax semantics. > > I think that's really an argument to align the behavior of resources and > objects, as it means one less BC break when resources are converted to > objects. Historically that's something we did in minor versions, so it's > good to reduce the amount of semantics that change when such a conversio= n > is done. Good point indeed! So +1 from me on the RFC. Not absolutely sure about the open questing regarding going one step further, but tentatively also +1 on that. Thanks, Christoph