Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107498 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67677 invoked from network); 11 Oct 2019 13:49:21 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 11 Oct 2019 13:49:21 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id CDDC42D203F for ; Fri, 11 Oct 2019 04:32: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-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) (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 ; Fri, 11 Oct 2019 04:32:28 -0700 (PDT) Received: by mail-qt1-x844.google.com with SMTP id n7so13335036qtb.6 for ; Fri, 11 Oct 2019 04:32:28 -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; bh=9WF8ItFh+FmmY00rK6clZgOV75vgc+B5woUAUKp0DWI=; b=vdufK0t4wuXi6sdI7mjY3T72qriPnAIwTv4VTeC+fJEwx6FfsugtsB54DPhVp8R2yG 7ZK9U5Qe+DUYr0DfpycH7nM5J67K1N4ZIyEzMpOeildCkABpeTki9Zz2l1Yc3SaOyq5t o7Gl548tybeFn82A0vm3ZGoNXGnw39paJcaRnBtOLwVE+lG1ts/USCGGjuulzoC0eJJ3 FHY8BPLLKv1GawWhBpVFffyIuXi//vCMcOB33wjLloUctFiK1J0BpBig5j/Sdj892sQj ZMmnd2BJm8TqUT3ytnf2kb40y6FJyeGa31VNg8IU+DN22jeGEt6mgNBBpYMSJYHP/ddg bMqA== 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=9WF8ItFh+FmmY00rK6clZgOV75vgc+B5woUAUKp0DWI=; b=ntpL2jsFuH1FWjTcB0TaVKYxobx/G8594YafPrD4hxGuP/dGqhzBYv5flHWbdfBYAO 1CyDUUQUHgpOlRRT1ukKqJaGVTjL5Mx172fG/duB7mSudhTjSuXY4zhu5Q4AHMifPHGs py0PhCZwfYRUy8xgX8c3PVhITaOLpqPF7T/bFlz0RjwPdqao+qIhh1LDqqkGbWDDW6Gu uUrB1uj2+ycMeE4u55sImKkfLlge5CMc2as+doJmNKCsVBm42kKsMgCIKiTfH5zEES7p f8sNyeaSPwdYkJEAInxovZWaQYjCYwtsK66alIY7WE33FMZcn5DQQeAbvtDxhsCUNwut Rz+Q== X-Gm-Message-State: APjAAAXTGc+IthsapWijVgQNpJCAR2LjbM0TOk8FWKxi2XD27/f9hd4a 8wPvWqI1uhgGgyLLsQyxZiMl8URo4rA= X-Google-Smtp-Source: APXvYqyppKlxF/NOniefkKkfLbpregr3ZL/Yu7SPZeiGxM6Jd9PU4SVBCjhoutsB6D8u0sndIUBzug== X-Received: by 2002:ac8:29e8:: with SMTP id 37mr14363984qtt.21.1570793547198; Fri, 11 Oct 2019 04:32:27 -0700 (PDT) Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com. [209.85.160.176]) by smtp.googlemail.com with ESMTPSA id a19sm5402572qtc.58.2019.10.11.04.32.25 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Oct 2019 04:32:26 -0700 (PDT) Received: by mail-qt1-f176.google.com with SMTP id n7so13334823qtb.6 for ; Fri, 11 Oct 2019 04:32:25 -0700 (PDT) X-Received: by 2002:a05:6214:1887:: with SMTP id cx7mr15498503qvb.123.1570793545037; Fri, 11 Oct 2019 04:32:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 11 Oct 2019 13:32:13 +0200 X-Gmail-Original-Message-ID: Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: text/plain; charset="UTF-8" X-Envelope-From: Subject: Re: [PHP-DEV] Re: [VOTE] Reclassifying engine warnings From: andreas@dqxtech.net (Andreas Hennings) On Fri, 11 Oct 2019 at 10:18, Nikita Popov wrote: > > On Thu, Sep 12, 2019 at 2:17 PM Nikita Popov wrote: > > > Hi internals, > > > > I've opened the vote on //wiki.php.net/rfc/engine_warnings. > > > > There are 4 votes, all of them independent. The first 3 are for specific > > cases that were controversial during the discussion, the last one is for > > the remainder of the proposal. > > > > Voting closes 2019-09-26. > > > > Regards, > > Nikita > > > > As people have expressed interest in hearing about direct technical > benefits that these kinds of changes have ... let me give you an example > that came up yesterday. > > Opcache performs a bunch of optimizations, and one class of optimizations > it does are subsequent jumps on the same operand. For example: > > if ($x) { A; } > if ($x) { B; } > > Currently, opcache will optimize the first if($x) condition to jump > directly until after the second if($x) if the value is false, on the > expectation that it is redundant to check the same condition twice in a > row: The result is going to be the same. Basically the result is something > like this: > > if ($x) { A; } else { goto end; } > if ($x) { B; } > end: > > Now, it turns out that this entire class of optimizations is technically > illegal. Why? Because $x might be an undefined variable! That means that > this optimization at the least loses an "undefined variable" notice, and at > worse changes control flow: > > set_error_handler(function() { > $GLOBALS['x'] = true; > }); > if ($x) echo "foo\n"; > if ($x) echo "bar\n"; To be fair, the same problem would still apply for other code that emits notices in an if condition, right? Or does the opcache only optimize this for simple variables? The "correct" behavior would be to analyse the code before the if(), and only optimize if we are sure that $x will always be defined.. Otherwise, we would need to convert it to if ($x) {..} elseif (variable_exists($x)) {goto end;} Sadly there is currently no variable_exists() in php, and the above code would probably lose the optimization benefit with the extra logic. > > Because it's been around for years and doesn't seem to have caused any > active issues, we're likely going to keep this, but nonetheless, it > illustrates the kind of issue we see with these notices. Either an > exception or nothing at all are fine, but notices caused problems. > > Of course there are also other problems, such as > https://bugs.php.net/bug.php?id=78598, which is one of multiple > use-after-free issues related to notices thrown during write operations. > The root cause is that under the PHP memory model, it is not legal to run > arbitrary user code while holding writable references into structures -- an > invariant that is violated by some notices, such as the undefined array key > one, because those notices may invoke error handlers. Again, either > throwing nothing or throwing an exception would be unproblematic. > > Generally notices thrown by the engine are a pretty big pain to deal with, > as well as something of a correctness and safety hazard. We have quite a > few bugs in this area, though most of them are thankfully not likely to be > hit by accident. > > Nikita