Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105634 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 17561 invoked from network); 7 May 2019 22:53:47 -0000 Received: from unknown (HELO mail-ed1-f41.google.com) (209.85.208.41) by pb1.pair.com with SMTP; 7 May 2019 22:53:47 -0000 Received: by mail-ed1-f41.google.com with SMTP id g57so19829133edc.12 for ; Tue, 07 May 2019 12:57:45 -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=IG6edYnnqsQeCgpdRlxtPSD1AvegobyJk7A3gwD1boo=; b=qnjHaMZHD+znv3DIfIeTiBmvCip3akRMXlNZ53sMl/d7wlAYqvgmU2ey3dI/L7al+6 OML9Iqx915kMB5/FbC/p3fZMz2oQxES9dgurNFmzZu3NMprCt+8vFsVtdf4zANaG9EQB w6dmF3+X9ZCdie7fNNxMMJK/6QSKbW7HYu8LmwNg1a2itsOSq07ezK6YTz+uIHDaeep0 lH2luLIMYbRK11dDUbLpeG9plWw22UufjUY6cVJR/rn4zVrsglsTGlW5OTW4avvZKlcz +C3bgzSAYhdvVWIrogqLlNl7DETPNLJZ/6XoqNMChLSy0gTTqAL3wJ3RVXCuqzTYFqm3 Zl2Q== 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=IG6edYnnqsQeCgpdRlxtPSD1AvegobyJk7A3gwD1boo=; b=Rdje/5gmu4pDSd23zb5+wp8W2ODIpWwe5+fYo4eKMh7F5hCW7fS4VrZqA7EKlwqt8Y baq/5TfZC6sq1apjoF7YXjkC2O8B0YA0q5rJBCXiqR+3obnJT89YID7A5Vi9RHBBFOdJ rnZBY00TCF+bO8VMP59Zchb1PFHQ5dCwqwIY2VAcFjPkAlx5HpeFB/gamuojBdAEZuXl THgE+YQrEjhiE5JzYIvcnWe05lhNTa+As1KAoDl/bj2JIIfzvovzJ2IRr4VbmeMeDBtI e27TwyxKD5gtwIsUw+GLPcQfAT5+eLrEYfZeRHKG/jAsPOagzW9PK0Bzd9uq+dKuLW3x pE5A== X-Gm-Message-State: APjAAAXVDPO+LJjT1dmEuyzVFxpJ8wSqI/OdACOy87qgC+3MGfxOW6De ves4VWG8Msks+MSR4fkurKQL8qcqXkaMNvuppOI= X-Google-Smtp-Source: APXvYqxgQQpq78uTv5nCqmoi8V4/HVm1fvd5AT7Uo3a2B13SaGjiGAAY7LAvDOmeDfCfnMULTy+5pkKdJRZVbTYl/S0= X-Received: by 2002:a17:906:ef1:: with SMTP id x17mr26140086eji.15.1557259064647; Tue, 07 May 2019 12:57:44 -0700 (PDT) MIME-Version: 1.0 References: <5cd1a0cc.1c69fb81.84b00.b914SMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <5cd1a0cc.1c69fb81.84b00.b914SMTPIN_ADDED_MISSING@mx.google.com> Date: Tue, 7 May 2019 21:57:18 +0200 Message-ID: To: Mark Randall Cc: Internals Content-Type: multipart/alternative; boundary="0000000000005f25da058851a189" Subject: Re: [PHP-DEV] Re: Error instead of returning false From: gen.work@gmail.com (Eugene Leonovich) --0000000000005f25da058851a189 Content-Type: text/plain; charset="UTF-8" On Tue, May 7, 2019 at 5:14 PM Mark Randall wrote: > On 07/05/2019 15:22, Gert wrote: > > 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. > > It comes up on various discussion forums every other month. There's a > few downsides to it, but mainly that any existing error handling would > need to be re-written as tests for the false value would never be > reached after the exception was thrown. > > It's a bit less of a hassle for more modern PHP design practices, as any > warnings are globally promoted to exceptions using set_error_handler in > userspace, but this too has its problems (for example in third party > libraries). > > IIRC, most functions are at least checking their input argument types > now and throwing InvalidArgumentExceptions, and the odd few like > json_decode have their exception behaviour, provided its flagged. The > new security focused stuff always throws (such as if there's not enough > entropy available). > > I don't think it's in any way practical to add throw-or-not flags to > every other internal function that could error out, and so there are 4 > options that I can see: > > 1. Make no change. > > 2. Everything throws. People have to re-write. The compiler would > probably need to further inspect the AST at compile time, and throw a > depreciation warning if the result of an error-able internal function > was tested for false. > > 3. Class (or namespace) level declares to throw on internal function > errors. > > 4. Leave the existing functions as-is, finally claim the \php namespace, > alias all of the internal functions into it, and make their default, > unchangeable behaviour be to throw a RuntimeException on error. > > -- > Mark Randall > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > For the record, there is already a library for option 3: https://github.com/thecodingmachine/safe Another option would be to introduce a new declare directive, something like