Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119128 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 86950 invoked from network); 13 Dec 2022 16:08:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Dec 2022 16:08:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8F6A9180559 for ; Tue, 13 Dec 2022 08:08:45 -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=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, MISSING_HEADERS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 13 Dec 2022 08:08:45 -0800 (PST) Received: by mail-yb1-f176.google.com with SMTP id d131so18209366ybh.4 for ; Tue, 13 Dec 2022 08:08:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=TfFID8IvLL2GSra4CYqcgOEZ2bZr8OC11/ffZZHWTYw=; b=g0IZfOIGB5clQmoS+K9KRb7rzUz0pin445JtrNFzIfhf1wa3i5QYmY9hAGa344WC+3 +PgMnvArPd+z0zbrFShWx3jhaKNSssTi4Q+OhZR/oBHlGwxXj5no9lNp+5zkn8kcS7Cl aOoNVMe1ng9mtnPDiWizJZ6SRprvm3RYpZYFc58/iSP8/f2gDtdSYvG8aCTe1hmByHoa Fw6qkITV1W1HpDtfKxMZ+iho+MR2/pjhR36USy5NljXkl6ACsJ77tMlGK+mqQf1jW44s M7XruW2cHB5IXZfdbOxYa65nkGyf4/usKdjouJ6QUq3mdliUceeJOqYeAdcDii3tOp3Z 6Y8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TfFID8IvLL2GSra4CYqcgOEZ2bZr8OC11/ffZZHWTYw=; b=EU1O1x1SeLr1W+nk6RAlhnK3NZLFyXZWKPMNGffzt+zoqp0aNsMdpzefuCkxo2JuYz P6YUQraZQ/HoHALGj6I629pX8Qr06pIz68BIRwJKOrUqpVCFNynZx6GslKMB/SqdsmKs /r/E9/c4P9xuCAwpBVXPxclVpQFGHMUe47pwqWietloioY6N+yrNxnmnh6QhNO2p2O1M 3xW5OZczF9731yrJKIAe9gynTl6orIlwSMIpxXsvLaWDIwE3agiskH53qZYUs84xYiK2 cGS/f0jpO+g3eRvfXwarUsvOKgiHztHWVJs8YfHA7G8CvtKfJO+Au5XgX3Ib6tIPv5an 1Nwg== X-Gm-Message-State: ANoB5pnmSpSCB9CIDBr5czNZkBDNNrA4g1F+/YqHufp6a9BtoJJytpix TK9Bae3D9LY9mH702QWq6lNBGRGndssx6qI+SLo5qyNY X-Google-Smtp-Source: AA0mqf4nqPf/lBrWyBiKK4/ugjVRsnu0TVJqQQSJolE5eDuxgIbwyTS2/J+WL4mMm8ltmGSNBfTP0WfjayCO1r/Odz4= X-Received: by 2002:a25:290:0:b0:6fb:5983:d192 with SMTP id 138-20020a250290000000b006fb5983d192mr35621306ybc.163.1670947724253; Tue, 13 Dec 2022 08:08:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 13 Dec 2022 11:08:27 -0500 Message-ID: Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000008ae0ba05efb7d5ed" Subject: Re: [PHP-DEV] Revisiting RFC: Engine Warnings -- Undefined array index From: dliebner@gmail.com (Dan Liebner) --0000000000008ae0ba05efb7d5ed Content-Type: text/plain; charset="UTF-8" Can I also just point out that by current definitions the "null coalescing operator" isn't properly named, it should be the "undefined/null coalescing operator". The only reason it is able to get away with not raising an error for undefined variables is that it's described as "syntactic sugar" for isset(), which is itself the exception to the rule for not raising undefined errors. Other languages, such as JavaScript, would raise an error for an expression such as `undefinedvar ?? 0`. And JavaScript conveniently offers the undefined primitive for precisely handling attempted accesses of undefined keys, while retaining the brevity and convenience of a truthy/falsy `obj.key` check. If you're set on raising errors and eventually exceptions for undefined key accesses, we need a concise, performant way to say `isset($varExpression) ? $varExpression : null` that's still way more concise than `$varExpression ?? null` that's baked into the language. On Tue, Dec 13, 2022 at 7:53 AM Dan Liebner wrote: > > No, code doesn't break. It now shows a warning instead of an error. > There is no behavioural change. > It breaks my app. Does that count? And didn't you follow up by referencing > this as "adding settings that change behaviour"? Does it change behavior or > not? > > > Adding a configuration setting to make this a notice on some > installations and not on others, would just mean that anything that needs > to be able to run everywhere needs to take care to not rely on the setting > either way, making it harder to develop portable code. > What code now relies on this raising a warning rather than a notice that > can't consistently deal with it by using isset or the null coalescing > operator? Or are you subtly referring to the fact that this RFC is a > stepping stone to escalating the severity to throwing an error? > https://wiki.php.net/rfc/undefined_variable_error_promotion -> "This RFC > proposes that accessing an undefined variable is rendered illegal behaviour > in the next major version of PHP, and will result in an Error exception > being thrown if it occurs." > > Here's another suggestion: > Make accesses to undefined array keys (objects, variables, etc) return a > new `undefined` primitive. That way, developers who are focused on writing > concise, readable code can continue to write and maintain code manageably, > and developers who are keen on writing a lot of code in a more "strict" > manner can handle undefined array key accesses consistently, without having > to rely on configuration settings. > > > just fix your code. > Practically speaking, I'd much more likely stay on 7.4 or migrate to Node. > > > On Mon, Dec 12, 2022 at 5:52 PM Derick Rethans wrote: > >> On 12 December 2022 22:20:27 GMT, Dan Liebner wrote: >> >> >It has been proposed to make the error level of "Undefined index" >> >configurable so that teams and individual developers can decide for >> >themselves how they want this situation to be handled. Given that: >> > >> > - PHP has been treating this as an E_NOTICE for over 20 years >> >> But not in the last three years. >> >> > - the change is a breaking change affecting many large codebases >> > ubiquitously (unless one were to unadvisedly suppress E_WARNING >> errors) >> >> No, code doesn't break. It now shows a warning instead of an error. There >> is no behavioural change. >> >> > - 7.4 is now deprecated >> >> Yes, as each release does 2+1 years. Which also means you've had 3 years >> to address this in your code base(s) already. >> >> >I think making the error level of "Undefined index" configurable is a >> very >> >reasonable suggestion, and I support it. >> >> Adding a configuration setting to make this a notice on some >> installations and not on others, would just mean that anything that needs >> to be able to run everywhere needs to take care to not rely on the setting >> either way, making it harder to develop portable code. >> >> We're also not generally anything near keen on adding settings that >> change behaviour , and suggesting to add one to make a warning a notice >> seems very far short of a bar that needs to be reached before many of us >> would agree to add a setting to make PHP less portable. >> >> Alternatively you can just fix your code. >> >> >Are we able to revisit this topic as a community and potentially bring in >> >more PHP developers from around the world to weigh in? >> >> You're always free to follow the RFC process, but I think you'll just up >> wasting your, and everybody else's, time with it. >> >> I can't see this being reversed, nor a setting added for, through an RFC >> process. >> >> cheers >> Derick >> >> --0000000000008ae0ba05efb7d5ed--