Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105630 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34622 invoked from network); 7 May 2019 18:11:48 -0000 Received: from unknown (HELO mail-ed1-f41.google.com) (209.85.208.41) by pb1.pair.com with SMTP; 7 May 2019 18:11:48 -0000 Received: by mail-ed1-f41.google.com with SMTP id p26so1236659edr.2 for ; Tue, 07 May 2019 08:15:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=igU5zQSfWbsXf2JtD47AjddXnjNjkOr/98nKQmfKCcE=; b=rWGg+SYz9YkPddru/mU+mEorerqQZaswd4Q8VOJRoovogFFQ+OHh63weKwgnxuLgSP hRvJ/fqyvRS9S4fGKB7JFgkIeL2bxAFp+v5rdi8XHRn6xGt6pqSyFH9J+IUA4I1z9Sq+ RH+EvPZgqLIjT05Hb8n1S/1oBsXDodUlFzCrvbkGGKrZkhjWU4InDr+sSZUwNl//pr/C wK+Dh2iPXOCF4IjlT1TtMHwkooTDRCY0ZfTWKTH8/XAdjawwmH3ad2CA0nQIsITGA8Jj t+GmsF1+l4c5NrkBf5mtkboPV9is3WvdVJEKU0LYY+kozofxdRkYCT3MiwM6G2xxSFek +yow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=igU5zQSfWbsXf2JtD47AjddXnjNjkOr/98nKQmfKCcE=; b=IS3Gt2HbOBmvrHP3ziNW5Hz9IYRbzLoV9xDEihBFZvuSLiAQTuRPv7/yhCZJLc5/lc LKlfm4Pa8T0y4QtZ+TpsOcIDdh7RnI5dAPvkMbVnAfQsIrT5e6nAFr01tsCjkKfoN1G4 aC/frX6ufgPf96jITXEkrmFyKELAhcOqPRG5AjzrHLoAEZw/3/4I6ZT0n8bLfD8r2ZHw qjCColXQPrw2jg9TGSXFBDnaDVrj2r3KJli1lKALzD9S/e405ZYF9zdtR1vop/94gzrK WIe4lf3OGl3c9pufjpntFaMyjiun47LdgOcDwRdb2dF75y+0GWQoHrEbbrSYJdZDe27o 5zFQ== X-Gm-Message-State: APjAAAUYLx/89xuWQxrK1+u4yBvd2v2VtwDDhD5clkpreFYSoB2tKjf+ zlt8GFpE9j2FletDXoi+mJ4= X-Google-Smtp-Source: APXvYqxK6cRKzpX7obHaVcSMlzgAHfeJjhq7o4dYH2jsuyFoAJB7XbOCqFme7QntvoBFDNFvDVGj3w== X-Received: by 2002:a05:6402:1499:: with SMTP id e25mr33029127edv.282.1557242143139; Tue, 07 May 2019 08:15:43 -0700 (PDT) Received: from [192.168.0.63] (84-75-30-51.dclient.hispeed.ch. [84.75.30.51]) by smtp.gmail.com with ESMTPSA id i45sm284874eda.67.2019.05.07.08.15.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 May 2019 08:15:42 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) In-Reply-To: Date: Tue, 7 May 2019 17:15:41 +0200 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Gert X-Mailer: Apple Mail (2.3445.104.8) Subject: Re: [PHP-DEV] Error instead of returning false From: claude.pache@gmail.com (Claude Pache) > Le 7 mai 2019 =C3=A0 16:22, Gert a =C3=A9crit : >=20 > Hello internals, >=20 > I wanted to propose an RFC, but i'd like to check first if this idea > has been considered before already. >=20 > 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. >=20 > 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. >=20 > Greetings, > Gert de Pagter (BackEndTea) >=20 > --=20 > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 The big issue, with your proposal, is, of course, migration of legacy = code: If you do think that ideally an exception should be thrown here, it is = better to devise a new function=E2=80=94and, while you=E2=80=99re at it, = a function that returns an object of some definite class instead of a = resource. Another issue is that a =E2=80=9Cfailure=E2=80=9D is not necessarily an = =E2=80=9Cerror=E2=80=9D. For example, when I use `strpos()`, I expect = that it returns sometimes `false`; and either using a try/catch = construct, or using a separate check beforehand would be cumbersome. =E2=80=94Claude