Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107659 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 7703 invoked from network); 24 Oct 2019 17:52:25 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 24 Oct 2019 17:52:25 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 5A8CF2D19B9 for ; Thu, 24 Oct 2019 08:38:51 -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,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE 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-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) (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 ; Thu, 24 Oct 2019 08:38:50 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id r68so7582271ybf.5 for ; Thu, 24 Oct 2019 08:38:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=BFGt8uEwX+dyTy5CIYFdW16tgHbLkFyhf8jPAW5diQs=; b=gmVSTGsPNNC/X5JORyVtJ0GzK/r9KfDXLG+oZ8D7PXufvd08IqFqs4EsoAIK4w9inM l5XmBK1byTe0qzTLHtXYohLqUAu8yzgew2fai5jUdFnWdiDSoyCy/ofBtWIJnbQNhnRb KCF6tPcJEalVkLZNXuHuic9F1vZ2zCQmsPRateRIUhJHR/dNKQv27s5JasmPMoYnEGkp JwkYQkGHD6f9RBSl6pBuAmEC5QJ9rkYJ3EQu2w+ua7jNKX5/RJV/qX6iTQVIO7r0Klfq 0WqNmQ2f3jtnncFQPS42rVPFsYSlWQmvmpgJ+oPq+JkX8b+oH6m7MKuWmlZQKBFlfc09 Pyyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=BFGt8uEwX+dyTy5CIYFdW16tgHbLkFyhf8jPAW5diQs=; b=Rf7Haqn2ZyBQPcb5wsiKYZfdDcA/lmZpwbsbpUbDR9FCUtWtEieIKqFWLCJCv9sp/v /GAFg4hyalmz4n7Dfa1mB1MfNx9QW8//gpchdOC0ataQbT+AM1MKQDYIBj91p4ZS7XEG tGCRrEXH3jdAejV/48mL9VzPzU6ZAPJSBWQRnIJSCBINHpo/PQGhTK1/18RZPn0GWzuD VfsM7CWWd5Ocb+1HitRmf4q2Y//l4vGA3bbX5YcBmrjZYoh6pY35jBTgo7+qcXrK3+0c Yiw0lWT6Vi10v+Ot6pb3D2AuVvKno/Qfq5wBRWLSOcA4AmfhjjcK60JPE4db6YOXg8U2 3CfQ== X-Gm-Message-State: APjAAAWkAqt4meB2x/V6+2LxfhlDFuUdCtwYt4EVkGnn3PJCow3b1Y9p k4A37Nro00akfT3L8cfgoBr+Xp+DQoQ= X-Google-Smtp-Source: APXvYqyNaKj+SoBiLSl/VF3Dpwm+d3KCP0zbC1VwxSQmFZWJ0UOhcTxfw5YpmzSw5nSuCq7UzDmCeg== X-Received: by 2002:a25:4a43:: with SMTP id x64mr11075905yba.37.1571931530186; Thu, 24 Oct 2019 08:38:50 -0700 (PDT) Received: from ?IPv6:2600:380:5e7a:d5d9:8804:5e9d:ce5a:94a? ([2600:380:5e7a:d5d9:8804:5e9d:ce5a:94a]) by smtp.gmail.com with ESMTPSA id r14sm6312296ywl.97.2019.10.24.08.38.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Oct 2019 08:38:47 -0700 (PDT) Message-ID: <11C11DE1-9D3B-4CB1-8226-AD48A0CE7A33@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_7FE32B78-49B1-47A6-B68F-55F7AD607C85" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Thu, 24 Oct 2019 11:38:41 -0400 In-Reply-To: <5f8115ce-0f89-c401-c8b8-9f865e76edd3@xs4all.nl> Cc: PHP internals To: Dik Takken References: <5f8115ce-0f89-c401-c8b8-9f865e76edd3@xs4all.nl> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Reclassifying some PHP functions warning as exceptions From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_7FE32B78-49B1-47A6-B68F-55F7AD607C85 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > On Oct 24, 2019, at 8:05 AM, Dik Takken wrote: > I fully agree. However I think the fear of having to add tons of try / > catch to existing code is exaggerated. I use Python a lot, which=20 > quite an exception throwing machine in comparison. Still, my code is = not > cluttered with exception handling. >=20 > So, converting a ton of warnings to exceptions in PHP does not worry = me > at all. I would welcome it, but not as a bulk operation. I agree that = we > need to ask the question for each case. I would still prefer the = answers > to bias towards exceptions though. It is not a "fear" for some, where fear is something someone worries = about that might be unfounded.=20 For me, at least, it is an annoyance I already have to deal with for = those things that throw exception, such as DateTime and DateTimeZone. =20= So not a fear but a preference not to make existing annoyances any worse = than they already are. #jmtcw > Or maybe introduce a try() function that can wrap calls. Since most - = ife > not all - functions would throw a single type of exception, the > following would catch that exception and return null in stead: >=20 > $x =3D try(fopen('missing.txt', 'r')) Now that I could really get behind. However, I might suggest it be handled slightly differently, based on my = experience with Go (which IMO does not handle in a optimal way.) Basically you want to be able to do something like this: if ( $result =3D try( fopen( 'missing.txt', 'r' ), $handle ) ) { error_log( $result->getMessage() ); return; } $contents =3D fread($handle, filesize($filename)); fclose($handle); Effectively I think we want to be able to easily tell as an expression = whether it succeeded for failed. Try() could returns either the = exception, if thrown, or false (or null) if no exception was thrown. = The called function's return value would be returned by reference as the = second parameter. > Here, try() would swallow only FileException, other exceptions are = still > thrown. I'm not sure if this construct is worth introducing though, = the > difference compared to a proper try / catch is much smaller. I would want it to capture every exception. Why not? -Mike= --Apple-Mail=_7FE32B78-49B1-47A6-B68F-55F7AD607C85--