Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108602 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65740 invoked from network); 15 Feb 2020 19:29:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Feb 2020 19:29:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DF9CC1804DA for ; Sat, 15 Feb 2020 09:44:12 -0800 (PST) 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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 ; Sat, 15 Feb 2020 09:44:11 -0800 (PST) Received: by mail-wm1-f42.google.com with SMTP id t14so14216585wmi.5 for ; Sat, 15 Feb 2020 09:44:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=mkOciBkGwJmNi6Vihao0uCoLDWfmEVzK7EH0BwS5j2M=; b=fkMEzTk8AAuGIlWULLhITSLTHSkg1DWCWMudOMBea2+u2mG9HCgeAfCdzjBHHCipWU 7fAlz9HeXhsDxrUR06ikQp6wu03Z8/6pOkbnMkg4pmLAIgmRVng+48TfRmIMO+sJS6ml w9Ily04Gk+zpMW1ifWiKnS003Qy4t9Ls0stQZIdrbsfO9M1EeTpe3TsgQ+bhQEUrKK0B Fdi8V1ZCG4HWFwpwQgqJfRRWyP8ULTWeWy1CmlRdmdpd+7j5MBl65NI7/U84d8MOgeua xhsTRM6afpbnOABO2CpMvyzQMi2PIRx3LiSKqtprKSuQqzp6qMXxOlDQj2NYdWnE+lHk gh4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=mkOciBkGwJmNi6Vihao0uCoLDWfmEVzK7EH0BwS5j2M=; b=q75cue47KtYD2JqDbJd5JZFpmyOCmb8ME68tFAE1YJivaKQJdOLU5lTycFC+Xx6FBl 4B7xw/DHeondcZkydjUOaY5zRaLXwFrQhy0aDREShnGyw1c0ExIn+M0tyoOAynF8K+YH k/ZqzPX5uTB1HaVYk2P3acohTzxi5HQQkjhjqW9l6K4EdEjgW/3TCDXwct/nhcPh+Aig C9Grvpm0czOF0LOOq6XZEi2cwmZO86E44Njg+7r2vKc2vqB/+kCFKauDwcafcnxDM47S hy/k7/9XxoACFQsws5Ri460t7BcZ1SU8dl14hHUxIn+bL20FFaQqwHXwrHpUIKyPF+tE jrkA== X-Gm-Message-State: APjAAAUfFJbsEVSv0zJOvGUo+S7hZC9+/MuOv0djhGlnPIhtZNU6+lbU 1vKZskfJHthOlEpzuE6RkaJME5BV X-Google-Smtp-Source: APXvYqxFm7nawiUP0DjEXLusIV6OirZuUIqCcd/4ZQNl/6CcKIIvnSDthDklap6TQb35rVxA4Zyv0w== X-Received: by 2002:a7b:c392:: with SMTP id s18mr11718729wmj.169.1581788647340; Sat, 15 Feb 2020 09:44:07 -0800 (PST) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id y12sm12463464wmj.6.2020.02.15.09.44.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 15 Feb 2020 09:44:06 -0800 (PST) To: PHP Internals Message-ID: <16481aca-93f4-43f5-5ec2-413d19ade318@gmail.com> Date: Sat, 15 Feb 2020 17:44:05 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Allow null variables to be decremented From: rowan.collins@gmail.com (Rowan Tommins) Hi all, There is currently an odd inconsistency when using the decrement operator on a null variable: $a = null; $a=$a+1; // int(1) $a = null; $a+=1; // int(1) $a = null; ++$a; // int(1) $a = null; $a=$a-1; // int(-1) $a = null; $a-=1; // int(-1) $a = null; --$a; // null I would like to propose changing this behaviour for PHP 8, so that --$a would give int(-1), as I believe it is simply a long-standing bug. This has been raised as a bug at least three times [1][2][3] but closed as documented behaviour / too much of a BC break. It is documented in the manual, but with no explanation of why it should work that way. [4] I would be interested in any explanations of why it might be intended behaviour, or ways in which people might be relying on the current behaviour. A proposal to change the behaviour was included in a wider RFC about standardising increment and decrement behaviour, but it never got beyond draft status. [5] I would prefer not to reopen that wider debate, but focus on this single issue. As far as I can see, the change would be to add a "case IS_NULL" branch to decrement_function in zend_operators.c to match the one in increment_function. [6] I will happily write up an RFC to formalise this, but wanted to gather people's immediate thoughts first. Links: [1] https://bugs.php.net/bug.php?id=20548 [2] https://bugs.php.net/bug.php?id=25674 [3] https://bugs.php.net/bug.php?id=41690 [4] https://www.php.net/manual/en/language.operators.increment.php [5] https://wiki.php.net/rfc/normalize_inc_dec [6] https://php-lxr.adamharvey.name/source/xref/master/Zend/zend_operators.c#2359 Regards, -- Rowan Tommins (né Collins) [IMSoP]