Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96028 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50634 invoked from network); 19 Sep 2016 13:05:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Sep 2016 13:05:04 -0000 Authentication-Results: pb1.pair.com smtp.mail=vpkaihla@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=vpkaihla@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.41 as permitted sender) X-PHP-List-Original-Sender: vpkaihla@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-lf0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:33900] helo=mail-lf0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 14/6B-19521-F72EFD75 for ; Mon, 19 Sep 2016 09:05:04 -0400 Received: by mail-lf0-f41.google.com with SMTP id y6so34831169lff.1 for ; Mon, 19 Sep 2016 06:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=feWdMfB1IILBXheWR2Ush/0t6ghHRw2tzKxTyGBEvjg=; b=MMc8bhCVmByJtaj3bFLogB1aPTMmGxSqMzOTtm/9p9S8bSm5RjeDTBttMty/VqQsfa 80nMaYoyD+RfOufS0brc1l4Nm/NRkorDm+GsaCOyXl6lyUsomOlMR4GNfxsxJFb4OvPQ TuZNcNBEGJ4r32gG9Mv5Pp9fYJmSOJIHx/EK19g39q9+ENscTqaeRJCEYpSfjLJAD6BZ t5qNAneiJfM/1Bk3q/pPdGGUbFN3CznwXOkP4PrVybZaaGDoX/CdwiL548a4I0+4lC98 p7yZNijumoxXUPuNCEqG/TyR00eJ3hCZHqDd6NFxH/eSppeMD40gT+fWuG0ZlL7h2Y11 2i3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=feWdMfB1IILBXheWR2Ush/0t6ghHRw2tzKxTyGBEvjg=; b=eYrcIfUNEZWlA2O9w6m6djbJgVZd0uJtgnJN3gwL8pyDoV5/VMDtcF4cBic0Jrg8Jd +ut6oJxRfAQKCnAwWyGpKRU9d7MgiA/axjQ24HNSHSHEoAQkNhquZL2hqsMWIcB3X+cS FYvpFjSnGP8Spk8CWdaBkrl7YQVlFNnv28YrUgAvGIrl1cr7HyDn2IusI7bztgiraNBl lLBTDV54gpLnzz7UU0KVLw4CSMKhFxKOX4wsECLEjndiaKc0I4LerkAxZrBDyexpJudA 79K0DCARuLVLQKE5KXzmian9PanVmxx6nc7TFjIpc9RSUOboRtRJmiBQF/ewGQJOLNUZ OXSw== X-Gm-Message-State: AE9vXwPYXPO5Kqf3xVNI3Xb78fT/RW3nM8fnONFrOgVY5kPMb/wmlgoz+pBJxjd6h24+Cv77XyWpUqtetl9JMg== X-Received: by 10.25.155.149 with SMTP id d143mr10660826lfe.121.1474290299383; Mon, 19 Sep 2016 06:04:59 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 19 Sep 2016 13:04:48 +0000 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=001a11401fba9735f6053cdbf547 Subject: RFC: Strict comparisons From: vpkaihla@gmail.com (Vesa Kaihlavirta) --001a11401fba9735f6053cdbf547 Content-Type: text/plain; charset=UTF-8 Hey all, I've been bouncing this idea of fixing all comparison operations in one fell swoop, although with an opt-in declare in the spirit of strict_types. Here's the gist: ==, < and > plus all the comparisons done inside switch statements and arrays are not very safe. === helps some, but does nothing for switches and < >. My idea is to add a strict_comparisons declaration that you can add at the beginning of a file in the same way as strict_types. The effect would be that all normal comparisons would make a type check before doing the actual comparison, and throw a TypeError exception if the types don't match. In other words: 1) { echo "This sorta works without strict_comparisons=1" . PHP_EOL; } ...would throw a TypeError exception after this change. This change would mostly go into zend_operators.c compare_function. So it would affect every comparison operation, including switch statements and things like in_array. I've implemented a prototype with a couple of test cases in https://github.com/paytrail/php-src/tree/experimental/strict_comparisons Please take a look and let me know if this would be worth a more official RFC. --vk --001a11401fba9735f6053cdbf547--