Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51797 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39622 invoked from network); 2 Apr 2011 22:55:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Apr 2011 22:55:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=sv_forums@fmethod.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=sv_forums@fmethod.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fmethod.com from 74.125.82.170 cause and error) X-PHP-List-Original-Sender: sv_forums@fmethod.com X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:37372] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/85-23967-B49A79D4 for ; Sat, 02 Apr 2011 17:55:08 -0500 Received: by wyb34 with SMTP id 34so4011734wyb.29 for ; Sat, 02 Apr 2011 15:55:04 -0700 (PDT) Received: by 10.227.27.98 with SMTP id h34mr2488862wbc.113.1301784904602; Sat, 02 Apr 2011 15:55:04 -0700 (PDT) Received: from pc ([83.228.56.37]) by mx.google.com with ESMTPS id u9sm2052293wbg.51.2011.04.02.15.55.02 (version=SSLv3 cipher=OTHER); Sat, 02 Apr 2011 15:55:03 -0700 (PDT) Message-ID: <22340D3B3D244B64B9B555E8E209206B@pc> To: "Jordi Boggiano" , References: <4D92CC38.5040900@toolpark.com><004301cbeee8$e54a8280$afdf8780$@com><4D9387BE.4030808@divbyzero.net><4D94984D.8060700@lerdorf.com><4D94A111.7050501@moonspot.net><520FB834-2614-4873-AC3B-0B2594B18471@roshambo.org><4D94A350.70201@lerdorf.com><4D94C380.2070402@lerdorf.com><7277ABA7-4B48-49FC-8974-512D4341CCC9@oettinger.dk> Date: Sun, 3 Apr 2011 01:54:59 +0300 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994 Subject: Re: [PHP-DEV] Adding a more logical string slicing function to PHP From: sv_forums@fmethod.com ("Stan Vass") > Looking at JavaScript which acts quite similarly to the proposed > approach, the Number methods [1] are not many and not often useful, > but still they exist. What happens if you do "3.3"->ceil() ? If ceil() > exists only in \numeric, you could say autoconvert, but if it exists > in both \string and \numeric we have a problem, so the only sensible > way is to drop type juggling for those autoboxed objects imo. Which is > also what JS does btw. If you have an ambiguous value on your hands, > you should cast it (x.toString() or parseInt(x)) first and then call > what you want to call on it. Another interesting to note is that JS > doesn't allow method calls directly on numbers - 3.toPrecision(2) for > example is a syntax error, you have to put it in a var first. I guess > it's not a problem since you should just inline the value you want > anyway, the Number methods don't do super fancy things. > > Anyway, I hope this helps, my point is just that you shouldn't forget > to check out how other languages solved the issue before hitting the > wall ourselves. Not saying we have to do it all like JS, but they have > something that works, so it's worth studying. > > Jordi Boggiano We could use the library organization of JS, in that purely math-related methods like 'ceil', 'sin' etc., constants like PI, E etc. will be in namespace \math and take any scalar numeric input. As a lot of them take more than one arguments, and the arguments are sometimes commutative, it makes less sense to present those ones in particular as methods. The few number methods that make sense as methods can then be in the scalar API. Almost like JS but not quite. Since's PHP's interpretation of types is slightly different than JS, we can surely take a page from JS, that's good (and I support it) but it needs to be nudged more towards PHP's PoV. Re. number literals, (3).toPrecision(2) works in JS, I guess they wanted to avoid some ambiguity in the parser, ex. 3.0.toPrecision(2). Stan Vass