Path: csiph.com!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1851737.v4KHZ1CCSF@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 12 May 2013 19:38:24 +0200 User-Agent: KNode/4.10.2 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <6JPjt.2779$7j7.1429@newsfe14.iad> MIME-Version: 1.0 Lines: 87 NNTP-Posting-Date: 12 May 2013 19:39:48 CEST NNTP-Posting-Host: 9226acdd.newsspool3.arcor-online.net X-Trace: DXC=k3f@UmWEH_0i6K;>iZ]763McF=Q^Z^V384Fo<]lROoR18kF Sanders Kaufman schrieb: >>> if(is_numeric('x11.11c') returns TRUE >> Try it without the quotation marks around the number. > > Which number? x11.11c is not a number. The misconception might partially draw from the fact that 0x11 is a number, the hexadecimal representation of decimal 16¹ + 16⁰ = 17 (even in PHP). In other programming languages that require a leading “0” and do not have “.” as (concatenation) operator, x11.11c could be the representation of decimal 16¹ + 16⁰ + 16⁻¹ + 16⁻² + 13 × 16⁻³ = 17.06958 (BTW, I have written a drop-in replacement for ECMAScript's parseFloat() that can do that, with the usual rounding errors [1]). In PHP, however, x11.11c would be equivalent to (x11) . (11c) which is a syntax error because constant identifiers must not start with a decimal digit, and decimal literals must not contain a letter: $ php -r 'echo x11 . 11c;' PHP Parse error: syntax error, unexpected 'c' (T_STRING), expecting ',' or ';' in Command line code on line 1 $ php -r 'echo x11 . 11;' PHP Notice: Use of undefined constant x11 - assumed 'x11' in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 x1111 $ php -r 'echo x11 . x11c;' PHP Notice: Use of undefined constant x11 - assumed 'x11' in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 PHP Notice: Use of undefined constant x11c - assumed 'x11c' in Command line code on line 1 PHP Stack trace: PHP 1. {main}() Command line code:0 x11x11c $ php -v PHP 5.4.4-15 (cli) (built: Mar 22 2013 15:41:03) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with XCache v3.0.1, Copyright (c) 2005-2013, by mOo with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans with XCache Optimizer v3.0.1, Copyright (c) 2005-2013, by mOo with XCache Cacher v3.0.1, Copyright (c) 2005-2013, by mOo with XCache Coverager v3.0.1, Copyright (c) 2005-2013, by mOo >> Quotes turn a number into a string. > > is_numeric() should return TRUE if the argument is a string containing > the representation of a numeric value. That's the point of this function. Not quite. It also works for non-strings as arguments. [2] is_numeric(1) === TRUE Thus it is better to say that is_numeric() returns TRUE if PHP's ”type juggling” [3] (or, more formal, “implicit type conversion”), if necessary, would allow the argument to be interpreted as a numeric value in an arithmetic expression. _____ [1] [2] [3] PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14