Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107004 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28449 invoked from network); 12 Sep 2019 20:54:31 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 12 Sep 2019 20:54:31 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 293CC2CC48C for ; Thu, 12 Sep 2019 11:30:28 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Thu, 12 Sep 2019 11:30:27 -0700 (PDT) Received: by mail-qk1-x72d.google.com with SMTP id q203so25480550qke.1 for ; Thu, 12 Sep 2019 11:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=8/YKKGG+bo1TWwcCr6ScUde3ZTPw4CRgBdYvF7bqSGU=; b=ushLTX3npppuXwHM3MADPt/W/dSU0ukvfvUsxdKO+o2hODAZ7UiFlukmZWp+95dA0x NLuvWWpevE9KIOLEXTaPOiRJPsaFYiLiCrh7YeaqIKEjrOm87jgUHFd03+MZ0RI1bB6V wM+oe7g1SDXKda9XGIb0DjbGwZUBPcbM8aSmOeRc5UYYNhCb8KiWdAh+z06F8OQTyHsm hWqV9XvYZ9K2PB/UevMswoCElZ4kJDShbIHOiHuavj6NfSD6ZK9UXUxhDolb5D5rFCbL xU7ysPYd405oGuW/sXXi1Qx34YDnl+LxbBY/UBcwjDPFP8Mouhbt4LUkfZdnjsB4HAWd uxoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=8/YKKGG+bo1TWwcCr6ScUde3ZTPw4CRgBdYvF7bqSGU=; b=dlcwlxwcJoNTf5i175yH0lWbymIqs5b5ZhXfkX+0aeBBRfgV3d95qqZA0N5+04HIkY T/4xWDyJI266chLRKrbeR7LbNg1k2JFkdH08iZ7Jbk77CaMFd/KD8Nj7CUAviykkQ27D PAtNz8ZLsu+/PAfZuHaoMmPs8rA2uxZKbAib5i4NUFEuMsM/pKkU6czbIcvYEHnUC7kb TV5uSAMgS08cTpl19owZSXA/R+HhyjTuVsFe7IuD3Vjwe36jU7YISbPfp6bl2T/6kMFA zJIXum+SOlOqMfKWdLqI0rLTMpi/YLRGir4nMt/BckMNzPBlvwl/FO+RoZ8FQZt7lVq/ NIVQ== X-Gm-Message-State: APjAAAXgZeU8mmj5bv5ALf35Z5FUXotUglj4ax+KkG7HO+fY0t0iHiko yANHsYD3xq4he52naKTxGWNyHcEc4OA= X-Google-Smtp-Source: APXvYqyRIFqhq7KbV/VecY1hsRoFThq9TZaIX1/6TIOjYUBrOuLyOu+VvYB6vA/a+lJCvYQfQ2CuJQ== X-Received: by 2002:a37:b041:: with SMTP id z62mr24700117qke.94.1568313026787; Thu, 12 Sep 2019 11:30:26 -0700 (PDT) Received: from mail-qt1-f178.google.com (mail-qt1-f178.google.com. [209.85.160.178]) by smtp.googlemail.com with ESMTPSA id x55sm16315865qta.74.2019.09.12.11.30.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Sep 2019 11:30:26 -0700 (PDT) Received: by mail-qt1-f178.google.com with SMTP id u9so4786455qtq.2 for ; Thu, 12 Sep 2019 11:30:26 -0700 (PDT) X-Received: by 2002:ac8:548:: with SMTP id c8mr3167379qth.124.1568313025054; Thu, 12 Sep 2019 11:30:25 -0700 (PDT) MIME-Version: 1.0 References: <076701d56978$86020910$92061b30$@php.net> <078e01d5697c$5512bc10$ff383430$@php.net> <31BD63BC-ACE0-4478-B241-E698D2D6F59C@newclarity.net> In-Reply-To: Date: Thu, 12 Sep 2019 20:30:13 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Lynn Cc: Mike Schinkel , PHP Internals List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Envelope-From: Subject: Re: [PHP-DEV] Changing fundamental language behaviors From: andreas@dqxtech.net (Andreas Hennings) Indeed, for the case of local variables that were undefined before, this can usually be fixed in a straightforward way by initializing to NULL. The goal here is to get rid of the error or notice while preserving the original behavior (even if it was buggy). This is IF this is your own custom code, or you have a strategy for maintaining patches on 3rd party code. (which you probably should). Another problem which has not been talked about much is code like this, which I have seen in multiple legacy code bases for Drupal 7 projects. Code like this is not considered good practice in Drupal 7, but it does exist. $element['field_category'][LANGUAGE_NONE][0]['#entity']->field_author_lab= el['en'][0]['value']; This is crying for "trying to access property of non-object". Because the values in $element were usually created "elsewhere", and who knows if the value at that position is an object? Even worse: This might go unnoticed 99% of the time, but in a specific edge case the value might not be initialized and the website would crash with error in PHP8. The "minimal fix" to preserve behavior 1:1 is to call if (isset()) or if (!empty()) on the whole thing before every such construct, even if at the moment you are not aware of cases where it might fail. In the "else" case, you do whatever would have happened before if the value was NULL. On Thu, 12 Sep 2019 at 20:10, Lynn wrote: > > On Thu, Sep 12, 2019 at 7:59 PM Mike Schinkel wrote= : > > > > > > > Just a few weeks ago I was refactoring some particularly horrible code > > developed by previously employed developers =E2=80=94 a code based that= has a 1400 > > line function and many other functions 100s of lines long, and I added = some > > initialization for variable and array elements prior to their use. > > > > Unfortunately my changes broke the code because the original developer > > using isset($var) as branching criteria. After finding this bug, I > > realized that this code base uses that technique frequently. I am know > > from lots of experience that this is a common technical among WordPress > > plugins. > > > > > The bug is not that you initialized the variable, it's that you initializ= ed > it with a different value: https://3v4l.org/8mB8B > ``` > var_dump(isset($a)); > $a =3D null; > var_dump(isset($a)); > > // gives > bool(false) > bool(false) > ``` > > Whenever one of these errors will occur, you can initialize either the > array key or variable with null and it will work again without changing > behavior. If anything, Wordpress shouldn't be an argument to not improve > PHP, though I think it's important to consider the impact of a change, > including for the Wordpress community. However, I think most people agree > that the quality of Wordpress code and Plugins is highly debatable. I don= 't > like the idea of not being able to progress because Wordpress users won't > upgrade PHP. > > Regards, > Lynn van der Berg