Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98428 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27193 invoked from network); 8 Mar 2017 15:14:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2017 15:14:10 -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.41 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.41 mail-oi0-f41.google.com Received: from [209.85.218.41] ([209.85.218.41:32913] helo=mail-oi0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/96-06022-0CF10C85 for ; Wed, 08 Mar 2017 10:14:09 -0500 Received: by mail-oi0-f41.google.com with SMTP id 2so20085388oif.0 for ; Wed, 08 Mar 2017 07:14:08 -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:content-transfer-encoding; bh=N8pE44neGY8Cd8vq0f349TTHMdj4UiIBdjc4v2G7VMI=; b=ZtrNxmH/FJYSLjJ5/SQ+7CRTOgFKDAqva6UUnSoahRrJFulLAR6H0uDj3+gUR7VQef c2v6udfNARh83CHs3mfODy7S6UgEZKCDKjN2skkqLsrawXf5vDEy8hewwQp2wbm4ielC c2xwELZUYoELc1H+9ylxwYOAp7Hn6MAwRK+Cw= 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:content-transfer-encoding; bh=N8pE44neGY8Cd8vq0f349TTHMdj4UiIBdjc4v2G7VMI=; b=qJsafyg4fe61r0vELwR4JLaNco7pPVjv956w+roGzbD5JDxpAY9B0LgTqKKsN4E9Gx BN4RWeeouCWlDUl/UydkFfJ8nT5qxvc6a6w2T1M74v/Nx/SEhmrKMFr9MY9VPPDDZMbX cnIbki9X4doZoSHX/JtvMpU73Iuwe50Zm3Pvi1wObKmpgcF7FhHDIb7WwmNYL9nqMbUH mRAakzmahvS+3LiqHO+XU+nlduH6YdVlTRjIqqN807tZwybTp0cc7a4S1TwQTbFGznpP DBNJxP3yMqDjZVlKbgRk5GuB19Kp0si1Mm4Ti07QYzpkzdqLKlzlRVB0Dqy93KkoWK0A BpBw== X-Gm-Message-State: AMke39nmKugnFoGHmgkkah1BymDlGd9tn7+Oa+/B20UNfqpaigpDn0nB6uxPTjJDzLvC+XPeoONcb0h0rsX+uA== X-Received: by 10.202.236.140 with SMTP id k134mr3425602oih.123.1488986045483; Wed, 08 Mar 2017 07:14:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.242.83 with HTTP; Wed, 8 Mar 2017 07:14:05 -0800 (PST) In-Reply-To: <8B230568-9074-4928-B9C9-F1F138054CD7@gmail.com> References: <8B230568-9074-4928-B9C9-F1F138054CD7@gmail.com> Date: Wed, 8 Mar 2017 17:14:05 +0200 Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [Discussion] is_string(), string type and objects implementing __toString() From: narf@devilix.net (Andrey Andreev) Hi Rowan, On Wed, Mar 8, 2017 at 4:29 PM, Rowan Collins wro= te: > Hi Andrey, > > I think this is an interesting area to explore, but do think the scope ne= eds to be widened slightly. > > > On 8 March 2017 12:25:54 GMT+00:00, Andrey Andreev wro= te: >>I ultimately wouldn't care if it's a separate function and did in fact >>think of an is_stringable() function, but wasn't happy with the naming >>- who's to say that e.g. integers aren't stringable? Bar >>horribly-verbose names like >>"string_or_objects_implementing__toString", I don't think there's a >>way to avoid that ambiguity. :/ >>If we want a "stringable" type though > > Sometimes, the fact that you can't think of a good name for a function is= a clue that the function isn't solving a well-defined problem. > > In this case, why *wouldn't* the function return true for integers? If th= e question the function is asking is "can this value be cast to string?" th= en the answer for any integer should be "yes". If the question is "will it = pass a strict type check as a string", then the answer for objects would al= ways be "no". Am I missing a situation where casting an object would be saf= e, but casting an integer wouldn't? > Well, it may be confusing and/or a bit inconsistent since what __toString() does is casting (and the idea will probably be ridiculed because of this), but putting that aside - it's not about casting at all. The question is rather "is this value a string?", only with the added assumption that __toString() objects are treated as "string objects" and thus fulfill the condition (another reason why I went for an is_string() parameter). It's not so much about whether casting would result in loss of data, which is what I assume you mean by "safe", but about whether the value was ever intended to be used as a string - an object implementing __toString() obviously is, while the same cannot be certainly said for integers. An integer can be a bit flag, or a key from an id =3D> name pair, etc. Cheers, Andrey.