Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106717 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42287 invoked from network); 28 Aug 2019 13:38:30 -0000 Received: from unknown (HELO mail-lj1-f181.google.com) (209.85.208.181) by pb1.pair.com with SMTP; 28 Aug 2019 13:38:30 -0000 Received: by mail-lj1-f181.google.com with SMTP id e24so2143082ljg.11 for ; Wed, 28 Aug 2019 04:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=sCx+ncCnR/7i1N2wRVbMa1HXkG6PyxD4CzXX3Q70pEo=; b=IyaTErTjsQEuxhMUbGdCXSlKzwCcl1tU2JR/8WqKQm1K9/YrvkDZ5116Du3rp5gcUn ch9piZkGvifg/NQZeXUVnpnOgVHx5LnDmQmBOnaNSE3froMTaAWnREQnmhskwf9U0iBL IfPDOJ/Cy4SnkteYJ0DsdbzOufrEu35Brq+/esWDeyPUZLG/DsFDSHaxEKYU6LHwb0p5 beOMr1E4j7hyqdDwiqyDrLUM+yTD/CzyHXQDF8WDOeZ12nry0fG3IxS+Ydm0/QonL+5f qeXGzyiIgsKyn/QOwglpmqwukToW9XBk2xN9wyZFhbRYYeVuKhoiZblAlSCfEmdPlUai MgyQ== 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; bh=sCx+ncCnR/7i1N2wRVbMa1HXkG6PyxD4CzXX3Q70pEo=; b=Rgk7Uzxl1f+YzLJlbFUgrVJFB6QhuepwRTsi+TS/IRTKOPhqE+Tu4MRpQrrKR/DUnT R8M3xf6hlQtLFqqPaVX9na7U25/i+ftjNr3mWEvCzS9YKHMv1+gdmldPhTz/CeuyQ6aB N7c3+LJ4qzMEnRME7vWRt8X5V3MZn6jTURfbAzM7ShHbegIHx3g1X5vkO0CJTKMXaLOE tIkOfX18q/owOrIODoS1xDZv4XZwYGuGtGylDPW5CQkkVrKp7TBSJM2pZm14J2PTdbPf JwePLqCgfvKVMqjkihBOR/GN6exoivMEZsb7MbDBpPEEkIg4g3wyVZHOyVdatJIIUSeu 0KGg== X-Gm-Message-State: APjAAAUDN1zEslQZr2KV1AiPJH9FHe12Raft5DsnCSFQJFrCgUhxT8kb w1jW898qLhQEV5ElylUf4cc4MDGXPBJN+QAMAEc= X-Google-Smtp-Source: APXvYqxbVLoJ9wAEYovxY/+9mWQxL3u5PWC54WtjMhd0WDiNr1znxWLbYdlewVqwfJ98i2kavw2P62+VhPTpvEyNsPU= X-Received: by 2002:a2e:65ca:: with SMTP id e71mr1736035ljf.61.1566990637583; Wed, 28 Aug 2019 04:10:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 28 Aug 2019 13:10:21 +0200 Message-ID: To: Zeev Suraski Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000051d07605912b70aa" Subject: Re: [PHP-DEV] [RFC] Reclassifying engine warnings From: nikita.ppv@gmail.com (Nikita Popov) --00000000000051d07605912b70aa Content-Type: text/plain; charset="UTF-8" On Wed, Aug 28, 2019 at 12:41 PM Zeev Suraski wrote: > > > On Wed, Aug 28, 2019 at 12:33 PM Nikita Popov > wrote: > >> Hi internals, >> >> I think it's time to take a look at our existing warnings & notices in the >> engine, and think about whether their current classification is still >> appropriate. Error conditions like "undefined variable" only generating a >> notice is really quite mind-boggling. >> >> I've prepared an RFC with some suggested classifications, though there's >> room for bikeshedding here... >> >> https://wiki.php.net/rfc/engine_warnings > > > Specifically on undefined variables, the way we deal with them has little > to do with register_globals. It's behavior you can find in other dynamic > languages (e.g. Perl), and allows for certain code patterns (which rely on > the automatic creation of a variable whenever it's used in write context, > and on a default known-in-advance value in case it's used in a read > context). It's fine not to like this behavior or the code patterns that > commonly rely on it (e.g., @$foo++), but it's intentional and isn't related > to any historical reasons. > This argument makes sense for arrays and objects (and I don't promote undefined index/property to exceptions for that reason), but I don't think it holds any water for simple variables. Writing @$counts[$key]++ is a lazy way to count values and avoid ugly boilerplate for if (isset($counts[$key])) { $counts[$key]++; } else { $counts[$key] = 1; }. But @$foo++ is just a really bad way of writing either $foo++ or $foo = 1. Outside of variable variables, the concept of a conditionally defined variable just doesn't make a lot of sense. > I think many (if not all) of your proposals make sense, but most of them > make sense as an opt-in - perhaps using something similar to Perl's strict > mode (which incidentally, changes the way the language treats undefined > variables in exactly the same way). This would also provide a future-proof > solution for additional similarly-themed proposals (such as strict ops, > etc.). > I don't think this is an appropriate use of an opt-in. It's a case where we can balance language cleanup with backwards compatibility concerns. Code that works after this proposal will also work before it, and as such there is no danger of ecosystem bifurcation that would need to be addressed by an opt-in. Thanks, Nikita --00000000000051d07605912b70aa--