Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98471 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 179 invoked from network); 10 Mar 2017 15:11:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2017 15:11:43 -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.52 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.52 mail-oi0-f52.google.com Received: from [209.85.218.52] ([209.85.218.52:32965] helo=mail-oi0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/A6-31244-F22C2C85 for ; Fri, 10 Mar 2017 10:11:43 -0500 Received: by mail-oi0-f52.google.com with SMTP id 2so52353661oif.0 for ; Fri, 10 Mar 2017 07:11:43 -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=cbGwFmq3BnGwOhhAwEEOQHWPmiOuErnlfMozAe+f7mE=; b=dWSiFzmGGorFkBSanMkNeofjLavFNqgjEGbHPVpNTr/MgYdw2crCecUE5ZUELyw79y VBO+4TgyyDezPMdBAecn5EmA30VNKoOTLqmJRJWEQG8LRgCGpdybQ+GOzEUWbTK2Ly6U 0/1kXtHQPBf8EiNgnTG50syzRisRLHVA6YtRQ= 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=cbGwFmq3BnGwOhhAwEEOQHWPmiOuErnlfMozAe+f7mE=; b=HAEzdKdho5F3qzvyiqkMOM7tVvlqTeayAgQxJ1tugIY6EKzHmefgrJmE5eY6/52nWV /D+GEF4kcBVvVexpyGJpZS7PfNy6RFz99Pluy3cSL5/3aOTVDuh6kSg/cRAByB7FcmX8 WJ9wgujmgfST6EcO3FrgQFnR8LLvoufsi9prmOYxoQHiexUiKd3KdUHxkPMkPJVESK+z VQ0+Fag4iWphC3MEVE+G4gXQ+q6wjVH6jb9rsNu2hStNbveUhwmLb2fuwx6Jn8eCLmRg 5iN+u/XJJjY5h8pt3Q4dZkrZKidTcjDadOi4PuE57ZrjEekvPg1KaUlYqp0m6VXrsuax hjlw== X-Gm-Message-State: AMke39k1OSYgKnCiljh33MKKc4Yaux5YVSA5FwsUyCGVsEwGunRJnMd6mAafYf6A7WPir9Q+vra/KlUJDYUX4w== X-Received: by 10.202.232.210 with SMTP id f201mr9070933oih.60.1489158700153; Fri, 10 Mar 2017 07:11:40 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.242.83 with HTTP; Fri, 10 Mar 2017 07:11:39 -0800 (PST) In-Reply-To: References: <24efb0e7-b0e3-68ed-5f42-2d5481f8f291@gmail.com> <44add374-6c4b-399a-c542-8d7f100dfaa3@fleshgrinder.com> Date: Fri, 10 Mar 2017 17:11:39 +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) On Fri, Mar 10, 2017 at 4:20 PM, Rowan Collins wr= ote: > On 10 March 2017 10:57:42 GMT+00:00, Andrey Andreev wr= ote: >>I'm not really interested in making "strict mode" less strict - it's >>already opt-in and non-enforceable. >>I want ways to write stonger-type code in "non-strict mode", because >>the fact that "strict mode" is non-enforceable means I can never rely >>on it. > > This is a common misconception - you can absolutely rely on strict mode e= nforcing your contract. > > Basically all that happens in non-strict mode is that if the caller write= s: > > foo($value); > > The compiler automatically changes that to: > > foo((string)$value); > > (That's not literally how it's implemented, but it's the effect you get.) > If I want to enforce strict_types=3D1 operation on the caller - I can't, it can always be overriden, and thus I can never rely on it. The fact that strict_types=3D0 will do casting for me has no relation to th= is. If there's any misconception here, it is that both modes are equal - if they were, we wouldn't have 2 of them. > As the receiver of that parameter, you can't tell, and don't care, if it = was the human writing the code who added the cast, or the compiler adding i= t for them. > You don't, but I do care at times. I want to know that the *caller* gave me what I want, and that the compiler didn't modify it before I received it. Why I may care about that is a different question, and nototiously hard to explain to people who don't, as all you'd always say something like "you asked for an integer and got an integer" ... Let's say I asked for one of 3 class constants, that happen to hold integer values, and you gave me a string that just happens to be castable to one of those values - you obviously aren't using my API correctly, but I have no way of telling you this because the compiled hid it from both of us. These cases may be rare and very specific, but they do exist and are valid. Yet for some reason, very few people around here want to admit that - all in the name of keeping PHP a weakly-typed language all the way. As if adding one feature would all of a sudden change your ability to write the same code you always did. Sorry about the rant, you can probably tell this irritates me a lot and I can't help it. I'll shut up now, just don't go on a mission to convince me otherwise - won't ever work. > You can't detect someone blindly writing "(string)" everywhere any more t= han you can detect whether they are running in strict mode. Nor can you kno= w if they took it straight from unfiltered user input, or copy-pasted a lit= eral string to 10 different files, or a hundred other things you'd really l= ike them not to do. All you know is, you asked for a string, and you got on= e. > ... exactly - uncertainty all over the place. :) Cheers, Andrey.