Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60071 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74405 invoked from network); 17 Apr 2012 11:20:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2012 11:20:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@googlemail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:58045] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E9/C0-03996-4025D8F4 for ; Tue, 17 Apr 2012 07:20:37 -0400 Received: by lahl5 with SMTP id l5so4804132lah.29 for ; Tue, 17 Apr 2012 04:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=CX11faWcyENgt0sNAdz4Fy7LwH8EWvYkIdNRaR0z3BY=; b=BC8fVPUZJ7Loti5PQ7EsQv4J8U9/Qg3TzdPekB2qZIP++R95yP9qa3eUD1NRR2FFv4 hjnCobzbpLy9liaBvfiEokxC1tTJXIZu/ee0Gx/8JcDiXLUe/f3x5QzZwPK/bI8pecvJ iCwmjJS/t7RSD7U80TpuyORX5cu3zljUTznpNC/38b+ZNY7N1jZ1NHw1DL829mS5tYNf TMxMD9zABRdFDr00lbLBfCep3RaMWz6EsCRccz1laIZjHRucUzeKWN6iZaYvzeWk/3Uy ng9Gj+Ep1wfv0lTceIqH24nejChfN1WWyU3pD+TRcmsyfgx7dpFzSMgqijsvPFNNq4GR JXQg== MIME-Version: 1.0 Received: by 10.112.84.103 with SMTP id x7mr2578362lby.52.1334661633523; Tue, 17 Apr 2012 04:20:33 -0700 (PDT) Received: by 10.152.127.68 with HTTP; Tue, 17 Apr 2012 04:20:33 -0700 (PDT) Date: Tue, 17 Apr 2012 13:20:33 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: is_numeric_string an hexadecimal numbers ("123" == "0x7B") From: nikita.ppv@googlemail.com (Nikita Popov) Hi internals! The internal is_numeric_string [1] function is used to check whether a string contains a number (and to extract that number). Currently is_numeric_string also accepts hexadecimal strings [2] (apart from the normal decimal integers and doubles). This can cause some quite odd behavior at times. E.g. string comparisons also use is_numeric_string, resulting in the behavior: var_dump('123' == '0x7b'); // true In all other parts of the engine hexadecimal strings are not recognized [3]: var_dump((int) '0x7b'); // int(0) This also causes minor problems in other parts of the engine where is_numeric_string is used. E.g. $string = 'abc'; var_dump($string['0xabc']); // string("a") // 0xabc is first accepted as a number by is_numeric_string, but then cast to 0 by convert_to_long But: $string = 'abc'; var_dump($string['0abc']); // outputs (as expected): Notice: A non well formed numeric value encountered in /code/8KXrYZ on line 9 NULL In my eyes accepting hex strings in is_numeric_string leads to a quite big WTF effect and causes problems and as such should be dropped. I don't think this has much BC impact, so it should be possible to change it. Nikita [1]: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.h#is_numeric_string [2]: http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_operators.h#131 [3]: http://www.php.net/manual/en/language.types.string.php#language.types.string.conversion