Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105627 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 24767 invoked from network); 7 May 2019 17:48:42 -0000 Received: from unknown (HELO mail-wm1-f68.google.com) (209.85.128.68) by pb1.pair.com with SMTP; 7 May 2019 17:48:42 -0000 Received: by mail-wm1-f68.google.com with SMTP id s18so7758196wmh.0 for ; Tue, 07 May 2019 07:52:37 -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=DNGEFXQ0v4OAXnHZZ8mJBaW+1TvdT/OZLyG3D+CWD3g=; b=SEMsApCfWYb15yF3DMd5rfVaWw3XVkDfu+Zx8o8m74b5D6iUCU4Cts62cEoSFMqZsL MOez32NhtBHnDrLMEoaEbIuD75RfmrSpZ+G7bCCXThXTRez5Y7rUard6C4cYmX6Plg8c 0KyA3ktwsrBEsjEjYb4jUyzU6BZpjy5LD7QzZKOPoGjgq3V6qMWzMZCWs1Q+xXhOcD8/ 2rwL4vl3eMcTvpFcNxk7k0/48mJakp6TpNI2p8TNgD/d2GlHmk/Qaj6P9pG5KcB07lYz 282YhxiuSpp2pzrfidlHLLNWZkY4N3u61g5y8w7ouJnjXTiW7eIwLikk52IUoQjlnFUl iLOA== 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=DNGEFXQ0v4OAXnHZZ8mJBaW+1TvdT/OZLyG3D+CWD3g=; b=BALlVs1ltL0WvxPUDmGVZNT3lAs2acAO2DUjdgLBlwZFMBbvZW2WGzK+sdyOj2Cqq+ TVg5W8DHPlbxAHApKautaxPSctdp7bP0lqnvqG2Kjoae2gija28g4po2wyGq5XAJu9Ko 6Ehb2ghbnqoUEXKpJcycDYRjrxaFlHldzKODy/HhPjEzpKlXDd9a9L/rDMu7gWkV0O++ zbmUwWRvzrij1sHNIESfYeR+/inf5WBIciHj1Hs8pX0lrJ6bZxqHOu5Xw40E/xKZbuE+ kBVwPf4uR0fpkxQfM7BQAHj0+CDB5SbSHeRaG1YPmTtvnsYzcISSkTMUCrof3UIxutGg ZvcQ== X-Gm-Message-State: APjAAAVkQAe8rK32wV6QzwTG13RGvpu+xTMWsjTAEIAgZl9x1oEXsKLO IlEPHexeAqzs/9vnCNi6KN83EKjYtDbcXm8TosM= X-Google-Smtp-Source: APXvYqxFEglf3b/6FiMCrXOzezd48gc/AefW14zQts0t5SVNR0khUHff8I/Cfx1LFlvL1IRa2zfV8PHfpNgyNSNSimA= X-Received: by 2002:a1c:4d04:: with SMTP id o4mr11569954wmh.126.1557240756964; Tue, 07 May 2019 07:52:36 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 7 May 2019 10:52:24 -0400 Message-ID: To: Gert Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000002613b805884d5ef3" Subject: Re: [PHP-DEV] Error instead of returning false From: chasepeeler@gmail.com (Chase Peeler) --0000000000002613b805884d5ef3 Content-Type: text/plain; charset="UTF-8" On Tue, May 7, 2019 at 10:22 AM Gert wrote: > Hello internals, > > I wanted to propose an RFC, but i'd like to check first if this idea > has been considered before already. > > My idea, extremely summarized, would be to take the functions that > return false/null when they 'error', and instead make them actually > throw an error. > > Currently, functions like getcwd or json_decode will return false/null > when an error occurs, and they populate a global error state, which > can be retrieved by error_get_last, or similar functions. json_decode > already got the JSON_THROW_ON_ERROR option in PHP 7.3, and this RFC > would basically make that behaviour default. This RFC would target PHP > 8.0, but i'd like to hear some opinions on this. > > This would be a pretty big BC break for those functions. That's not necessarily a bad thing, but, I think the burden for justification is larger than just adding a new feature. These are the questions I'd ask 1.) What is detrimental about the current behavior? 2.) What is beneficial about the new behavior? 3.) Are the items for #1 and/or #2 big enough to justify breaking existing code? 4.) Is there a way to achieve the desired behavior without a BC break. My initial thoughts are that impacts of the BC break would be pretty big. EVERYONE using json_decode without JSON_THROW_ON_ERROR will have to modify their code. It's not a quick find/replace change either. Instead of checking the return, and then checking the error state (or, maybe they are OK with just continuing if there is an error), now has to wrap the call into a try/catch block. I personally don't see anything that detrimental about the current behavior or that beneficial about the new behavior. It's not like try/catch is that much simpler from an implementation standpoint that checking a global error state based on the return value: $foo = json_decode($bar); if(false === $foo){ //get error and do whatever to handle it } vs try { $foo = json_decode($bar); } catch (\Throwable $t){ //do whatver to handle it } It also appears we can easily provide the functionality you desire with additional options. You mentioned that json_decode has already been given a new option, JSON_THROW_ON_ERROR. What is the advantage to making this the default behavior vs letting people specify the flag when they want? If there a reason adding such an option as a new parameter wouldn't work for other methods, like getcwd? > Greetings, > Gert de Pagter (BackEndTea) > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Chase Peeler chasepeeler@gmail.com --0000000000002613b805884d5ef3--