Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76652 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55096 invoked from network); 18 Aug 2014 13:20:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Aug 2014 13:20:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=addw@phcomp.co.uk; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=addw@phcomp.co.uk; sender-id=permerror Received-SPF: pass (pb1.pair.com: domain phcomp.co.uk designates 78.32.209.33 as permitted sender) X-PHP-List-Original-Sender: addw@phcomp.co.uk X-Host-Fingerprint: 78.32.209.33 freshmint.phcomp.co.uk Received: from [78.32.209.33] ([78.32.209.33:53660] helo=mint.phcomp.co.uk) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/00-54989-3ADF1F35 for ; Mon, 18 Aug 2014 09:20:36 -0400 Received: from addw by mint.phcomp.co.uk with local (Exim 4.72) (envelope-from ) id 1XJMrQ-0004Fk-4A for internals@lists.php.net; Mon, 18 Aug 2014 14:20:32 +0100 Date: Mon, 18 Aug 2014 14:20:32 +0100 To: internals@lists.php.net Message-ID: <20140818132030.GI28522@phcomp.co.uk> Mail-Followup-To: internals@lists.php.net References: <53F1094B.4040100@mabe.berlin> <53F1F534.50109@mabe.berlin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <53F1F534.50109@mabe.berlin> Organization: Parliament Hill Computers Ltd User-Agent: Mutt/1.5.20 (2009-12-10) Subject: Re: [PHP-DEV] [RFC] Binary String Comparison From: addw@phcomp.co.uk (Alain Williams) On Mon, Aug 18, 2014 at 02:44:36PM +0200, Marc Bennewitz wrote: > >What exactly is wrong with ===, strcmp(), etc..? > > The question isn't "What's wrong with ===, strcmp()?" but "What's > wrong with ==, <, >?". > > We have a standard way to compare two operands but currently we do > some magic things to solve something that don't need to be solved. > > If you would like to compare two pears we currently convert the > pears into apples and compare two apples and say please use a > special function to compare two pears. Why? > > There is no numeric context to compare two strings numerically. I don't want to start a flame war, but perl gets it right, you have 2 sets of operators 'eq' and '=='. The choice to have a type juggling '==' was made years ago, that should not change. If you want '<=' with strings, use strcmp(). There is also a speed cost to type juggling (PHP 5.3.3, 64 bit centos): $a = "1234"; $b = "ghij" $a == $b is about 64% slower than $a === $b strcmp($, $b) is about 163% slower than $a === $b $a = "abcd"; $b = "ghij" $a == $b is about 24% slower than $a === $b strcmp($, $b) is about 168% slower than $a === $b $a = "abcd"; $b = "4567" $a == $b is about 20% slower than $a === $b strcmp($, $b) is about 176% slower than $a === $b $a = "1234"; $b = "4567" $a == $b is about 20% slower than $a === $b strcmp($, $b) is about 162% slower than $a === $b -- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include