Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105628 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30569 invoked from network); 7 May 2019 18:06:01 -0000 Received: from unknown (HELO mail-ed1-f67.google.com) (209.85.208.67) by pb1.pair.com with SMTP; 7 May 2019 18:06:01 -0000 Received: by mail-ed1-f67.google.com with SMTP id w37so19059849edw.4 for ; Tue, 07 May 2019 08:09:56 -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=yJjmHzMen3yZ/NDjTyk518Zr6EMw706BXg3sVbRDHY4=; b=HpGDhEpb7xWy9S07pf53HzloAceXdahi5GsDKrO6T83h9ms+7SLKH8/rxEdAj/BlDc v07lPxWkwFjFlnwcdf74SoHPcB+5YLSiDaxaJ7H7kCK4hGqOtQcoHmW77wZ2U6OAwkg3 AtP1tSQcqfrcG/v16U7UOxjAWHr0pNv0bQ82qX5vIoEET5CGTZkf00nIS7EF1NKUH6UK 6XMeSf5eRs6ZHMB3W3UlOlvgZvt42dz0Fu9VGjssZxFrde4KMsBIEKF0N7uBhEhQcEMG eD0FeJw0m4pvch5P2s6gs4zSmGuTJXNx9F271vCcb6/RfLMj1f5r+OBJta9MLx16TBYG uBCA== 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=yJjmHzMen3yZ/NDjTyk518Zr6EMw706BXg3sVbRDHY4=; b=DSD8zExvJR4hYAlwjiqfah2hmN4kPjnaH+SKQ2PdyGsEBB90OWAEUDmH4222cKpoPp KqfpHuAIFX1+MICvQFbzm1NHO2c2mNJlMR4Pjj6sH5fq3qkv5ea3HEfTqsRv36nLO5gq hTCKkNaI37lXJloP5K3TFMMKe1GTtv/QKW93ZBUYiD4oh5EvTZu/VJes2twR+0RxuBDu WTYsB7sOt7rz//5x7JD8O5Y0veLEIA27kHUKgkNgvizs9PsczlVrW86INcCFFrSIy+01 OyKFMFlC0pfdFk62b+wYktG7LVZbiAOP+uuZCGBvj8tKhrxY3b/u6gW7CRuKyK30YPXJ 6b9w== X-Gm-Message-State: APjAAAWZ97pPsk2/SHBC8cWXkQUwm4mzjOq+cqU2YSlb6SzXFSGesg7Y imCEBAtGBKyB0qnBL/YOPUV3QN42ySspztdX9azS1q+Wshk= X-Google-Smtp-Source: APXvYqxCxglr02rKIziCofc5xTTEdLPC2Mv1J1KzztMrFuz9XqOZj8l6AmYus/4BaIvF7XtCUK12BdJyoIqRvtshrO0= X-Received: by 2002:a17:906:bc2:: with SMTP id y2mr24903282ejg.98.1557241795668; Tue, 07 May 2019 08:09:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 7 May 2019 17:09:38 +0200 Message-ID: To: Gert Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000f725405884d9c24" Subject: Re: [PHP-DEV] Error instead of returning false From: nikita.ppv@gmail.com (Nikita Popov) --0000000000000f725405884d9c24 Content-Type: text/plain; charset="UTF-8" On Tue, May 7, 2019 at 4:22 PM 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. > > Greetings, > Gert de Pagter (BackEndTea) There's two cases to distinguish here: 1. Error conditions that indicate a programmer error (what we would throw an Error exception for nowadays). 2. Error conditions that indicate a data/environment/etc error (what we would throw an Exception exception for nowadays). One large category of warnings of the first kind has already been converted to TypeErrors in https://wiki.php.net/rfc/consistent_type_errors. And I'd be in favor of changing more of these in PHP 8. This is (relatively) non-intrusive from a BC perspective, because these conditions are not something you should ever explicitly check for: If your code hits them, it is simply broken. However, what you seem to have in mind here are error conditions of the second kind. I don't think we can change these on any timeline. Current code (that is careful about handling errors) will be checking false/null return values for them, and throwing an exception instead would be a major and very hard to automatically fix BC break. The proper way (imho) to handle an eventual migration to exceptions is to introduce new APIs that supersede the existing ones. E.g. if we ever get around to introducing an OO API for the stream layer, than that would be the time to also introduce use of exceptions. A possible alternative would be to control this behavior in some way similar to declare(strict_types). Regards, Nikita --0000000000000f725405884d9c24--