Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75447 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60693 invoked from network); 14 Jul 2014 13:12:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2014 13:12:49 -0000 Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=indeyets@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: indeyets@gmail.com X-Host-Fingerprint: 74.125.82.44 mail-wg0-f44.google.com Received: from [74.125.82.44] ([74.125.82.44:47888] helo=mail-wg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/F2-43645-F47D3C35 for ; Mon, 14 Jul 2014 09:12:48 -0400 Received: by mail-wg0-f44.google.com with SMTP id m15so3984941wgh.3 for ; Mon, 14 Jul 2014 06:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :message-id:references:to; bh=opGuqrYU9la+Ug4rmZXX2RGXz8VoFWJLbUjRMSJvb+o=; b=VoUKrKXKEDRdLAuQsaxGisXkJtJSH2euN1AZ4f+3B9irRPfRkmaol0VFLLE1+0VdC1 IRF05kFB3yZdFGvx9jY+jn7jNzwkiRX6e7D+chGL6k2zWHQaWWdkjmk74Tq9V6NpVYTv OzeIZ38cjopi2gH8VCPZp6oUBpu0pOQcl9uLzRbVIvdP0C+nI7kIzWN/tOq4xH7p8iTI gBdH3B94dTHayYzfxvhWx9rTcj+wznLYBLx8KYNVNJ78LiLfqHNcTa3ELA5dBNR/o9ca n4CnZWWqx8kedCLBOON5+zWLZ2Lyo7TyxnuBWBW8zBKsm2K2vKvcsBTNIjU4rISDhQHL oYLQ== X-Received: by 10.180.20.112 with SMTP id m16mr25087153wie.6.1405343561939; Mon, 14 Jul 2014 06:12:41 -0700 (PDT) Received: from [192.168.1.26] ([92.255.5.146]) by mx.google.com with ESMTPSA id h13sm25469598wjs.2.2014.07.14.06.12.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 06:12:40 -0700 (PDT) Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: multipart/signed; boundary="Apple-Mail=_D89F75DC-578B-4A02-AFB1-8603EA5808F9"; protocol="application/pgp-signature"; micalg=pgp-sha512 X-Pgp-Agent: GPGMail 2.1 (fa3e4a3) In-Reply-To: <16D48604-0C0A-4613-91A4-21392E3A2636@ajf.me> Date: Mon, 14 Jul 2014 17:12:18 +0400 Cc: PHP internals Message-ID: References: <08503591-EFC8-48E6-984E-FFC292C5EA5F@ajf.me> <16D48604-0C0A-4613-91A4-21392E3A2636@ajf.me> To: Andrea Faulds X-Mailer: Apple Mail (2.1878.6) Subject: Re: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening) From: indeyets@gmail.com (Alexey Zakhlestin) --Apple-Mail=_D89F75DC-578B-4A02-AFB1-8603EA5808F9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 On 14 Jul 2014, at 16:58, Andrea Faulds wrote: > One of the issues with the RFC as it stands is how to handle bool = casting. While int, float and string only allow lossless casting (with = the exception of objects, but we can=92t really do anything about that), = bool=92s behaviour at the moment is quite different. I don=92t think it = makes sense so I won=92t discuss the current behaviour, only possible = new ones. >=20 > One option is simply to forget about being lossless and make the bool = type hint accept any value, meaning any truthy value or any falsey value = would yield what is expected without error. This would ensure that if = some stupid programmer (like myself ;) has passed in a non-boolean = truthy/falsey value to your function, it=92ll be handled correctly. It = would mean all your bit hacks ($foo & FLAG etc.) would work, anything = you got from $_GET (e.g. ?foobar=3D1). However, this is unlikely to = catch bugs in code, because literally any PHP value would work. For that = reason, I=92m not sure this is the way forward. I don=92t think that "scalar casts=94 should do any additional = error-catching. they target a very different usecase. It shouldn=92t guarantee correctness of the whole program. It should = guarantee that variable types are fixed inside of function. In my opinion, this patch should act 100% similar to zpp. And if, at some later point zpp-behaviour changes similar change should = happen to userland "scalar casts" Some people talk about inconsistency, which is introduced by reusing = same syntax for "strict parameter types" and "scalar parameter casts=94. = There=92s some truth there. Let=92s use different syntax. This might work: function foo((int) $a) { var_dump($a); } I would read it as declaration-level casting -- Alexey Zakhlestin CTO at Grids.by/you https://github.com/indeyets PGP key: http://indeyets.ru/alexey.zakhlestin.pgp.asc --Apple-Mail=_D89F75DC-578B-4A02-AFB1-8603EA5808F9 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iQEcBAEBCgAGBQJTw9dFAAoJEMkJcRxZdR27POsH/2LtsXn9Bk8oiIa3MtePPJV9 9LjK4SzrGpaDKf7U8sAtFh/DVzKhONDbFSu3nznQhkKLox+b1oZGm+hgoDU0poGb 40jJV1yAr/96lU9kNlN9hbWJe5RsBN7I3qh2ghUNCslC6ota1lGpWD/r4qP6E26o THid//7KLUXTZ8JQk1BNhNtWxGLZaumTB9IkqaJPch7PqLklxSAT0aGgF+gN9rvt jq7YxBzAqyK5UyEZStPUJoqz4qJgZw4y9oHf6nHtLEyh7HtSHYInN9ltIFxy416X BsIY/oq6B2MXYnrybZN9td+PQmBkZgKjpDqp4J+l1rfxvvcEaPktAh5dsSETfuw= =xnUa -----END PGP SIGNATURE----- --Apple-Mail=_D89F75DC-578B-4A02-AFB1-8603EA5808F9--