Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98479 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56963 invoked from network); 11 Mar 2017 13:23:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2017 13:23:20 -0000 Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.53 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.53 mail-oi0-f53.google.com Received: from [209.85.218.53] ([209.85.218.53:34535] helo=mail-oi0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/11-38004-74AF3C85 for ; Sat, 11 Mar 2017 08:23:20 -0500 Received: by mail-oi0-f53.google.com with SMTP id m124so62448615oig.1 for ; Sat, 11 Mar 2017 05:23:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=TluRyKUIn6RhjZ64D/Mb3Fns+lz3tvGakO0DoASzn64=; b=MOtrDS4AmoTUhoJcmLbR7ufHxzP7radqzbhQQ0fB4tEffO7WFKS3q60sOkSCVnSXbN l0YkdlfwtsqW8Rc/ta/uWsFZBvOzm3itnn75RLhf/R1UXDcap4xJT1lb6Qm1mqyRyBqk BdxMB9Tguypsp7k3tV1Nbh8mqvRn//eaHTrWc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TluRyKUIn6RhjZ64D/Mb3Fns+lz3tvGakO0DoASzn64=; b=QsD4JdbUI4r7+ifi1pgPvlZHLvIMOvRGhKHHmhn+kKMmWJzM6tnL8OGlhm7yOpwtXk kpBWVnYHttyK/WiQkhJtx2EA7Yn/eC/d+r54iGWajBl2/lIc5oFLFc3c7qqv2K5S1FUX k8bS8o3A0fjEn+ZSeVAHZAqOxa3gt//0cmkCDj9I+YeX9dEnrOEWoRPlCKqnifaBLx/w FaEmotQ0vjxZ6Zn01gA0wW6iouFZV2d+Bd71MXEFiAQVHF/GLgTc8Sl/Ji/9kzm6lbub LOW1setOtGzFrNXNYt5IHM73PEjYKsaDqLHcZyamakC1zh5kniunmZNlQ+qKtOFG0QDk Y86Q== X-Gm-Message-State: AMke39lKreB4l4V8vGyUBB7pCnYKbs4Ql76dFKIsSr8txQBV2dQCEporscRmUQ/fnq/GJcG13Fm60PXpgRQaFw== X-Received: by 10.202.232.210 with SMTP id f201mr11263852oih.60.1489238597063; Sat, 11 Mar 2017 05:23:17 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.242.83 with HTTP; Sat, 11 Mar 2017 05:23:16 -0800 (PST) In-Reply-To: References: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> <44add374-6c4b-399a-c542-8d7f100dfaa3@fleshgrinder.com> <2AB030D8-9677-4E0E-8215-07D77910E51B@gmail.com> Date: Sat, 11 Mar 2017 15:23:16 +0200 Message-ID: To: "internals@lists.php.net" Cc: Rowan Collins Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [Discussion] is_string(), string type and objects implementing __toString() From: narf@devilix.net (Andrey Andreev) On Sat, Mar 11, 2017 at 1:39 PM, Fleshgrinder wrote: > On 3/10/2017 11:57 AM, Andrey Andreev wrote: >> Yes, they're valid string values, but the examples I gave were meant >> to show that context can make them predictably invalid, and hence why >> strict typing is desirable. > > I am totally in favor of strict types, but having a union of some type > and having the ability to constraint to it is strict. The union of > bool|int|float|null|string is stricter than the super type mixed. That's > the whole point of having a stringable. > We already have an unambiguous name for that: scalar > On 3/10/2017 4:11 PM, Andrey Andreev wrote: >> You don't, but I do care at times. > > Sorry, but your example makes no sense at all. Just because you got an > int does not even remotely mean that one of those constants was used. I'm sorry, I thought I wouldn't have to explicitly state that of course I don't know a constant was used ... "constant" is not a type. The important thing is that I know a constant was *not* used. Apparently, I am bad at examples, but take a look at sort(). Yes, even after I validate the $sort_flags values, I would never know if you passed int(1) or SORT_NUMERIC. However, knowing that no sane developer writes sort($array, 1), I can very reasonably tell you that the following is an error: $foo = '1'; sort($array, $foo); And the mere existence of SORT_FLAG_CASE makes it that much important that an error is triggered, as now my logic would be built with bitwise operations and I can't just check for one of X values. Ironically enough, the following code executes silently: $array = ['a', 'b', 'c']; sort($array, '2234234324'); If you don't see the problem with that, I guess it does make "no sense at all" from your POV. Just agree to disagree. Cheers, Andrey.