Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80850 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49563 invoked from network); 20 Jan 2015 01:45:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 01:45:15 -0000 Received: from [127.0.0.1] ([127.0.0.1:8357]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id CA/B0-41341-923BDB45 for ; Mon, 19 Jan 2015 20:45:13 -0500 Authentication-Results: pb1.pair.com smtp.mail=me@kelunik.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=me@kelunik.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain kelunik.com from 81.169.146.221 cause and error) X-PHP-List-Original-Sender: me@kelunik.com X-Host-Fingerprint: 81.169.146.221 mo4-p00-ob.smtp.rzone.de Received: from [81.169.146.221] ([81.169.146.221:11528] helo=mo4-p00-ob.smtp.rzone.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/D4-18613-4135CB45 for ; Sun, 18 Jan 2015 19:43:01 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1421628178; l=3731; s=domk; d=kelunik.com; h=Content-Type:To:From:Subject:Date:MIME-Version; bh=hxNuPKETjWoCEI71WFkG/5AUWic=; b=hZfhCP7187hwum1Ks3EhCfrVOCMobYaniEAlR/ctCJMsWJpASbVp+Gwl5KJpvVlYgG7 d12ayJuh2G3UBYJ1qtLZ9VQmOWgCiuWFmvIjU5OfqeV1GBGeTuHde2wNkrA1m0hvs3yw8 0Vy6CUI2j1mq3oWfmGp7kDeqxwFmbuKABeA= X-RZG-AUTH: :IWkkfkWkbvHsXQGmRYmUo9mls2vWuiu+7SLDup6E67mzuoNNBqD/uc8= X-RZG-CLASS-ID: mo00 Received: from mail-wi0-f179.google.com ([209.85.212.179]) by smtp.strato.de (RZmta 36.3 AUTH) with ESMTPSA id 307c70r0J0gwOHd (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) for ; Mon, 19 Jan 2015 01:42:58 +0100 (CET) Received: by mail-wi0-f179.google.com with SMTP id l15so3734986wiw.0 for ; Sun, 18 Jan 2015 16:42:57 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.180.97.195 with SMTP id ec3mr30246567wib.79.1421628177927; Sun, 18 Jan 2015 16:42:57 -0800 (PST) Received: by 10.27.200.193 with HTTP; Sun, 18 Jan 2015 16:42:57 -0800 (PST) Date: Mon, 19 Jan 2015 01:42:57 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=f46d0443066e8c5605050cf69add Subject: in Operator From: me@kelunik.com (Niklas Keller) --f46d0443066e8c5605050cf69add Content-Type: text/plain; charset=UTF-8 Hello, I'd like to propose a new feature to PHP: The in Operator Bob mentioned a few weeks ago he wants such an operator in PHP and today I stumbled over http://nikic.github.io/2012/07/27/How-to-add-new-syntactic-features-to-PHP.html again, which uses the in operator as a sample. Use cases: $obj = new StdClass; $obj->prop = "value"; $languages = ["PHP", "C", "Java"]; var_dump("PHP" in $languages); // true var_dump("Python" in $languages); // false var_dump(0 in $languages); // false var_dump("0x0" in ["0e3"]); // false var_dump("prop" in $obj); // true var_dump("foo" in $obj); // false var_dump("Hello" in "Hello World!"); // true For strings, it would replace `strpos("Hello World!", "Hello") !== false)`, for arrays it would replace `in_array($needle, $haystack, true)` and for objects it would be a replacement of property_exists($class, $property)`. This change would mainly be syntax sugar, but I think it's worth because: * `"0x0" in ["0e3"]` would return false while `in_array("0x0", ["0e3"])` returns true, that's probably an edge case, but there may be a lot of people that don't use the `$strict` parameter, see http://3v4l.org/0K7E5 * It would solve the issue that it's hard to remember the order of the arguments for in_array and strpos, just had to look it up again. Bob would volunteer to implement that feature. Best Regards Niklas Keller --f46d0443066e8c5605050cf69add--