Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92485 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17750 invoked from network); 19 Apr 2016 19:19:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Apr 2016 19:19:24 -0000 Authentication-Results: pb1.pair.com header.from=bishop.bettini@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bishop.bettini@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.196 as permitted sender) X-PHP-List-Original-Sender: bishop.bettini@gmail.com X-Host-Fingerprint: 209.85.214.196 mail-ob0-f196.google.com Received: from [209.85.214.196] ([209.85.214.196:35207] helo=mail-ob0-f196.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/35-22821-BB486175 for ; Tue, 19 Apr 2016 15:19:23 -0400 Received: by mail-ob0-f196.google.com with SMTP id 4so2604517obi.2 for ; Tue, 19 Apr 2016 12:19:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:from:date :message-id:subject:to:cc; bh=uKxiuB9T6tJn0PbsLEa5rnamPptXvi2uRSDAIMvgbag=; b=f7r0q6WSrCgLL0hoOj/7zHiDyRdza7/WXag+wLPNVIXrHuRX/NOAN1FjrSzRYMUCFB oHFc6Wm7Of1BaBCwbO0MphN0QMhPLJu2sACY5UWmm4zoYFZnZVSUBir2FjIHW0tlS0W2 d17Hkh2L6ASK5h8Jvw+7IyzRgboSFRCMJs+5kQBgEhaA520702y6PcYEh3R+Jhaj/1FC xlkcQegVBMJ3EuKU7v99R+YW/Y+jyvU0DQ0Ua390wEJ6toyfUFIxcf2KUSkZ+xs/+rp8 e0BYPpntG73BPi2hw75eLkeWbZr+xv3Bbkde4rtchLWsOaTj4FtGGnCVRkN8laut/Yid fYLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:sender:in-reply-to :references:from:date:message-id:subject:to:cc; bh=uKxiuB9T6tJn0PbsLEa5rnamPptXvi2uRSDAIMvgbag=; b=CwOCrrjrIKZMS9GVFEDWmwnP0YpEtZgVgwgMS3hsrvabQXSjMhBZCSYpmS+RLZTp3l iJwHrvgPKCT6U7l8celjCHn9kLsN3ZcIYfVVdklQsrHXoEZQvJK4Q/LmJcYr2K+rhvUC WvYmqLQywOjCAGwmA/EWmCjcBTDXAT9q1ZZvgARA+DABeYBJi93x+IRbVyTZ60Aoz8d/ QRO2686eDKmi0cAS543Ib3GwDw9T5YX1ag6VWL386LlvlhtQdlUehrbeHE4n3uiPqojd gn6bxp6PIKeLpKcx+QAi1StqLooqaoyKYgutd8a2XaYDSvNe3nAg8In9RlZN+qCuzVL9 GTZg== X-Gm-Message-State: AOPr4FVX6x+s3tY38+xUpBbUGtUpX66g85jys16WZtiuxZmd5kuJeB0Q+hd+qSXQD0hnOS7U+eAE/GyMnARhQA== X-Received: by 10.60.123.41 with SMTP id lx9mr2077101oeb.55.1461093560262; Tue, 19 Apr 2016 12:19:20 -0700 (PDT) MIME-Version: 1.0 Reply-To: bishop@php.net Sender: bishop.bettini@gmail.com Received: by 10.157.36.137 with HTTP; Tue, 19 Apr 2016 12:18:50 -0700 (PDT) In-Reply-To: <5716755E.1040807@gmail.com> References: <571581C7.7010901@gmail.com> <571589AF.3090502@gmail.com> <5716755E.1040807@gmail.com> Date: Tue, 19 Apr 2016 15:18:50 -0400 X-Google-Sender-Auth: pCel24xvVD2wUgEQW6pBrMHpXQA Message-ID: To: Stanislav Malyshev Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7b5d5ffca4a5ea0530db5afc Subject: Re: [PHP-DEV] [VOTE] Catching Multiple Exception Types From: bishop@php.net (Bishop Bettini) --047d7b5d5ffca4a5ea0530db5afc Content-Type: text/plain; charset=UTF-8 On Tue, Apr 19, 2016 at 2:13 PM, Stanislav Malyshev wrote: > Hi! > > > namespace Application; > > function log(Eloquent\Collection | Haldayne\Map $entity) { > > $logger->log($entity->toArray()); > > } > > This is bad design. It assumes that two completely unrelated classes > have the same function and it means the same. Both of these exist in the wild, and both have identical function wrt toArray: reducing a set of collection-like things to an array of arrays. > If it's indeed true, we > have a way to express it. It's called "interface". Except these two are in separate libraries that cannot share an interface. > > "Ugh, this is much easier in multi-catch. If only functions took > > multiple types, this would be much simpler to write." > > And it would be completely wrong, abuse of typing. If you mean to say > "anything that has [toArray] method", you should either have interface or > just get rid of the strictness and duck-type it and rely on PHP to throw > exception if anything happens. Otherwise it is just a sloppy design. > An interface is not possible: separate libraries. Duck-typing is not appropriate: only these two specific classes are supported. Union types solve certain problems better than equivalent run-time checks. Multi-catch solves certain *other* problems better than equivalent many-catch. They are orthogonal, but the syntax is similar: *"into this block, accept this type or this type or ...."* I contend that this apparent similarity must be consistent, lest we earn another sadness. --047d7b5d5ffca4a5ea0530db5afc--