Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83084 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65966 invoked from network); 18 Feb 2015 15:34:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2015 15:34:09 -0000 Authentication-Results: pb1.pair.com header.from=patrickallaert@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=patrick.allaert@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.44 as permitted sender) X-PHP-List-Original-Sender: patrick.allaert@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:58969] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5E/D1-56339-0F0B4E45 for ; Wed, 18 Feb 2015 10:34:08 -0500 Received: by mail-wg0-f44.google.com with SMTP id k14so1889840wgh.3 for ; Wed, 18 Feb 2015 07:34:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:references:from:date:message-id:subject:to :content-type; bh=JEIDNpDjhr3klYAqwPsvl62q50PoRshuyLKLZnXkNMs=; b=Gz52h2PZvPhz+rWPiedeEQ2qHZ8Tk9ftYkB3OoFUkrbBnGFrQz58TuaPUge2+omFY7 IGERtKVbXwPX50VKKCXsvkbzvZO012kjusThxf0i9cEJnBLic+wgN3liqNYwYCyMzrOz PEeEFt2SkjeetwBYN8zKWj8NpEH9MkOMVzT4TXkyrtuwIccuA2z55j32iKWs9CKZZlOd l67JBQmq8unNK8pj0eujJUz9r3FTwY2E+ybJZ11NbqZmAskUIPxb0xX8aVjUwBKervCh ipDDcyhO8JkcJmaD6uegJt9VHsXZNCgZc6K/l/if/vTaEKfKBPylqBQpphhRBp1BVCSZ Edew== X-Received: by 10.194.210.103 with SMTP id mt7mr75021098wjc.103.1424273643379; Wed, 18 Feb 2015 07:34:03 -0800 (PST) MIME-Version: 1.0 References: Date: Wed, 18 Feb 2015 15:34:02 +0000 Message-ID: To: Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary=001a1133625493a298050f5e8c5f Subject: Re: [PHP-DEV] Scalar Type Hints v0.4 From: patrickallaert@php.net (Patrick ALLAERT) --001a1133625493a298050f5e8c5f Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Sara (and thanks for continuing the work!) Le Tue Feb 17 2015 at 23:04:20, Sara Golemon a =C3=A9crit= : [...] > 2) Define a way to enable "strict mode" (we'll be weak by default). > [...] > 3) Tighten up coersion rules for weak mode. i.e. "10 dogs" for an int > is a violation, but "10" is acceptable. > Regarding 2) and 3): An option might be to implement "weak mode" only and configure the coercion rules "reporting" in a similar way than with the error_reporting configuration entry. Not focusing on the details here, but I think about something like: function foo(int $a) { var_dump($a); } ini_set("coercion_reporting", 0); // current PHP 5.x behaviour foo(7); // int(7) foo("7"); // int(7) foo("7 dogs"); // int(7) ini_set("coercion_reporting", COERCION_WARNING); // Warn, but do not fail in case of potentially bad coercion foo(7); // int(7) foo("7"); // int(7) foo("7 dogs"); // Warning: Unsafe coercion transforming "7 dogs" to "7". // int(7) ini_set("coercion_reporting", COERCION_ERROR); // Fail in case of potentially bad coercion foo(7); // int(7) foo("7"); // int(7) foo("7 dogs"); // Catchable fatal error: Unsafe coercion transforming "7 dogs" to "7". The biggest advantage, IMHO, is that you get the exact same result whether you do: foo((int) $value); or: foo($value); ... whatever the mode you are in. Basically, this is weak type hints + something similar to what I contributed in the past with the "Array to string conversion" notice (see: https://github.com/php/php-src/commit/d81ea16e). Care to share the pro's/con's you see with a solution like that? Thanks in advance. Cheers, Patrick --001a1133625493a298050f5e8c5f--