Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98448 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73357 invoked from network); 8 Mar 2017 23:32:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2017 23:32:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.51 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.51 mail-oi0-f51.google.com Received: from [209.85.218.51] ([209.85.218.51:35641] helo=mail-oi0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/2E-06022-5A490C85 for ; Wed, 08 Mar 2017 18:32:54 -0500 Received: by mail-oi0-f51.google.com with SMTP id 62so28505308oih.2 for ; Wed, 08 Mar 2017 15:32:53 -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=lYGe9z5KuZBj1dqBtk6Nxpm40DC1hM7JHUeBIGk/olU=; b=V1XCdSjwlQolMk14s7keB2R3LKvS3ksA+0+2aydgXzcycfG55hnAF9AJVU0K8/3h5D 09YCwjnKgjbMFgMtHkypIpsk3K34FhHhy1H0D4vrbfMlKFESd7+S2NIifSa63+sAPY2b AiIMAu7Gm+t5DMPHk3aRo+/Txarape1ofKCJ4= 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=lYGe9z5KuZBj1dqBtk6Nxpm40DC1hM7JHUeBIGk/olU=; b=pzHkgqeqKFCKi5FE//rEmkeU4NVccOPdq0ulLRtRpVGcGsAOn1jNQcScxhVa4DLp6y s4Sw+Fy6DQ2iH89bD+E84miKDQZFmJN9RgIJ2gVIlL8iHYuyNhRGUozArLWwdPDvZ1c1 QxB+Zzs3O+2ld9o3whPSRvN3gTMzeJNSQHsNrwZ+0XL79sneK+KgXlf0laO5fLF5GB3D kR/duTjuFzNOw55PsEmS7QE+xzd4ccW5pKywGkYvv1u1Y5hXfYZNqCKhetu5XJ2Fhu7x 9yow4tUYDQsEwBHjLjlkcagilyGEeq0w+tf2qH/n+datql6Xsmnsum9iqYeogbbOcV29 JvnQ== X-Gm-Message-State: AMke39nGMT/H/aBXd+6TWxBSQNzlwDCwElVtUGgtIiW0geAySflPq4KPFcDRVsTDB5VJq8K++XbC4sjGRWYjYw== X-Received: by 10.202.89.3 with SMTP id n3mr5659379oib.26.1489015971161; Wed, 08 Mar 2017 15:32:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.242.83 with HTTP; Wed, 8 Mar 2017 15:32:50 -0800 (PST) In-Reply-To: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> References: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> Date: Thu, 9 Mar 2017 01:32:50 +0200 Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" 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 Thu, Mar 9, 2017 at 12:42 AM, Rowan Collins wrote: > > I still don't understand what you're using this check for that means you > want to exclude integers. If you're passing on the value to anything that > actually needs a string, you're doing a string cast, either explicitly or > implicitly, so there's no difference between me passing you (string)'42', > (int)42, or new class { function __toString() { return '42'; } } > This goes all the way back to the heated discussion about scalar type hints ... Being explicit is the entire point, and why many people wanted strict typing. On Thu, Mar 9, 2017 at 12:43 AM, Fleshgrinder wrote: > > What is the use case where every other scalar (and null) type is not > acceptable? I defended that stringable should bridge only string and > objects with __toString too first, but after thinking more about it, > there is no real world reason why one would need that. Almost all use > cases I can think about evolve around strict mode and some function that > simply does not care what it was. Hence, stringable would truly act like > the into trait in Rust. > Think of value objects. Perhaps you'd have a few methods on a value object, but mostly use it to give context to a scalar type value. For example, a Cookie object may have the cookie attributes (domain, path, etc.) as value objects, but they can easily be created from raw strings, while other types would be ambiguous. A similar effect could be desirable for HTTP headers. Also, we're talking about strings here only because we don't have __toInteger(), __toFloat(), etc. I'm not saying we should, but if we did - similar use cases would be present for other scalar types too. Even easier to imagine - a DateTime object would probably have __toInteger() returning a UNIX timestamp. Cheers, Andrey.