Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83918 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66334 invoked from network); 26 Feb 2015 19:36:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2015 19:36:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.223.181 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.223.181 mail-ie0-f181.google.com Received: from [209.85.223.181] ([209.85.223.181:46687] helo=mail-ie0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 85/AC-32582-CA57FE45 for ; Thu, 26 Feb 2015 14:36:12 -0500 Received: by iecvy18 with SMTP id vy18so19853210iec.13 for ; Thu, 26 Feb 2015 11:36:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type; bh=zZzi9g2UD07Sb2EmOB8Zx+QJpxcjFlurDfgpdiJPDvk=; b=P5B/2ZPIiMR4eLTHFWgJzCuvuqZzeA/m6ZY/qaBwQECzwqaP+drstP+BoqdW9jBQHO upv5XAmD0Nyu3Ze3ZzGm/FXBG6/BLSnK38ryRQ3RtDtH8rp+FwCjbf4sV+vxi8tuRuqq Ai4gna3hI7K8vTV6C5mJ60ejE5l77/vROUoq3Yn+Cslpi9A9K0gJ+FGipl/U+hBxyvT9 hITKOuXzvHH9tqO4kkHBcmUskfiimGXxs9ZdVwkTnVEbagvZtZVL9UpZz6kew2Ow1uBI idP4p7wZCenuXUqeamwrrC8cMXbsppebmpmGie83ueJaEijfvNloJCS64S0e7yVJsogT 8KVA== X-Gm-Message-State: ALoCoQlFfDZ9J7mfoZOEQ1Y92AV2ZcDyOz5GIDz9owTg5RBc62s/1Z+CYXmEt1N4cRUraD/EkHmV6W2PHO9DOoKfd49KqwNF6/RLklxdd/LYgUezf15PRbL8RLJfryQpOXVojudP/7p60hapfvloG9JczLBI2UkJvQ== X-Received: by 10.43.103.8 with SMTP id dg8mr11525241icc.18.1424979369046; Thu, 26 Feb 2015 11:36:09 -0800 (PST) References: <3d639901ae85227b219e7ee59b3140fe@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGwbbdURx2shUG2o7Zj2Ywptu8MnAHNhHseASj3TG8CBU/YnAHY8IsNnQx0NDA= Date: Thu, 26 Feb 2015 21:36:08 +0200 Message-ID: To: Anthony Ferrara , Mike Willbanks Cc: Dan Ackroyd , Theodore Brown , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] A different user perspective on scalar type declarations From: zeev@zend.com (Zeev Suraski) > -----Original Message----- > From: Anthony Ferrara [mailto:ircmaxell@gmail.com] > Sent: Thursday, February 26, 2015 9:29 PM > To: Mike Willbanks > Cc: Dan Ackroyd; Zeev Suraski; Theodore Brown; internals@lists.php.net > Subject: Re: [PHP-DEV] A different user perspective on scalar type > declarations > > Mike, > > One point of clarification: > > > This is true, however, the types that you are receiving back form a > > multitude of data sources might be in a mixed format (databases for > > example often provide representation back as a string, non-json based > > web > services > > provide mainly as a string, etc). While I know what my data looks like > > and I know I am always going to get a "string" integer back I do not > > want to have to type cast this each and every time. Or that I have a > boolean > > integer representation that is in a string... You get the point. Sure, > > I > > could certainly go in and take 5 minutes and cast each one but I'm not > > certain why the purpose is there... It specifically changes the > > determination that PHP is a weakly typed language and all of a sudden > > I now need to care that my string integer boolean is not actually a > > boolean. > > It's funny that you bring up boolean... > > With the current coercive proposal, you will still need to worry about the > types: https://wiki.php.net/rfc/coercive_sth#coercion_rules That's true, but a lot, lot less. > Passing boolean(false) where an integer is expected will generate an > error. > This is a common practice, specifically around internal functions. > Example: > https://github.com/sebastianbergmann/phpunit/blob/a4e23a10d4eeea5fd9f > e8916859a07430b94cf42/src/Util/ErrorHandler.php#L58 It's actually not nearly as common as one might think, and arguably - it's may be hiding bug or at least some misunderstanding about the semantics of the argument (not always, but sometimes). Warning about it (as deprecated) makes perfect sense. I'm going to send some data from real world apps later today or early tomorrow. Spoiler - not a lot of breakage at all, and coercive rules seem to have a remarkably good signal to noise ratio. > The difference is with the dual-mode RFC you can choose not to have to > cast > and keep everything as-is today (or more specifically, you need to > explicitly > choose strict mode). And you can have user-land behave identically to > internals **in both cases**. Put another way, coercive gets to keep a single, sensible conversion rule-set in PHP - with relatively minor updates needed over the course of several years. And contrary to what might be implied here, it would require a LOT less casting - while still taking advantage of much better data sanitation. Zeev