Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70626 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30082 invoked from network); 13 Dec 2013 12:54:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2013 12:54:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.176 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.176 mail-ve0-f176.google.com Received: from [209.85.128.176] ([209.85.128.176:47589] helo=mail-ve0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/9F-32587-9630BA25 for ; Fri, 13 Dec 2013 07:54:02 -0500 Received: by mail-ve0-f176.google.com with SMTP id oz11so1311554veb.21 for ; Fri, 13 Dec 2013 04:53:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=gMUd1o/i1X5VOp46slaem3syTzBbEUVO7FqsbLWCvOw=; b=d7lkVf4Wwcey99vIUmjm7TKW8ojiGSTIqz+94Fc5eHCxdM0adMf6SjY+kovsfxaLdr UZGjEoo71Afr35iM+GESj2HlhU63OicpLSDocHdOolK2FmZVnZgmVb/88Ze3cxscbRek TjK+YLd27HoR/eEHXt3lFVE+NNOC2Y9/depXXAfpS5nNn7F5IazxAwiNtV3askaXMg5l rAcmoj1NGzK1rODpdBT+Wh1QQ5n+O2ZxLoec3vW7K31rQ1ktwp8UFtue231Fx/zEZCbw rNbpc0AFZaUSG6G9CNKvPIS34uPhzBUXJEiwuDEAOYwbIOZbBPPh1EqYyctdq1LSqmM6 t00A== MIME-Version: 1.0 X-Received: by 10.52.160.130 with SMTP id xk2mr927977vdb.24.1386939239030; Fri, 13 Dec 2013 04:53:59 -0800 (PST) Received: by 10.58.128.33 with HTTP; Fri, 13 Dec 2013 04:53:58 -0800 (PST) In-Reply-To: References: <52AA1649.2090601@ajf.me> <52AAA1EA.7030106@marc-bennewitz.de> Date: Fri, 13 Dec 2013 20:53:58 +0800 Message-ID: To: Kris Craig Cc: Marc Bennewitz , PHP internals list Content-Type: multipart/alternative; boundary=089e0160caaeaaeb2f04ed69f486 Subject: Re: [PHP-DEV] [PROPOSAL] Alphanumeric decrement From: tjerk.meesters@gmail.com (Tjerk Meesters) --089e0160caaeaaeb2f04ed69f486 Content-Type: text/plain; charset=ISO-8859-1 Hi, On Fri, Dec 13, 2013 at 8:00 PM, Kris Craig wrote: > > > > On Fri, Dec 13, 2013 at 12:15 AM, Tjerk Meesters > wrote: > >> Hi, >> >> On Fri, Dec 13, 2013 at 3:09 PM, Kris Craig wrote: >> >>> On Thu, Dec 12, 2013 at 9:58 PM, Marc Bennewitz >> >wrote: >>> >>> > Hi >>> > >>> > Decrementing "a" to a number isn't a good idea because on incrementing >>> > again you will increment the number and not go back to "a". >>> > >>> >>> Why not just have "a" decrement to an empty string (i.e. "") and an empty >>> string increment to "a"? >> >> >> Imagine a scenario in which an empty posted value is assumed to be a >> number and so ++$x is applied; instead of getting the expected "1" they now >> get "a" which, after an (int) cast will become 0 .. surprise! >> > > Yikes, that's a good point. > > Ok, so just to play devil's advocate here, would it be completely awful to > have (int) "a" == 1, (int) "b" == 2, etc? I'm not advocating this, mind > you. In fact, I hate the idea, but I think it bears mentioning as it would > resolve the problem you mentioned (while no doubt creating a whole bunch of > new problems). > > >> Then a decrement on an empty string could trigger >>> a warning and remain empty. That way, we won't have situations where >>> decrementing from "a" and incrementing back would output a number. >>> >> >> Actually, the increment of "" is "1", which is still a string; the >> increment of "1" is int(2), though. >> > > Also a good point. It sounds like applying incremental behavior to > non-numeric strings using standard arithmetic +/- operators might prove to > be prohibitively problematic in such a loosely typed language as PHP. > > >> >> That said, isn't it bad enough that php already has exceptions such as: >> * ++$x is not always the same as $x += 1 >> * ++false remains false, but ++null becomes int(1) >> > > I agree. I've never liked either behavior. > > >> >> If decrementing strings should work, I would request to also make ++false >> => true and --true => false >> > > I'd be for that, actually. > > >> >> Lastly, if I could go back in time I would have created str_inc() and >> str_dec() so that + has a unambiguous meaning :) >> > > Honestly, I don't think it's too late to do that now. At very least, > those functions could be added without modifying the existing +/- behavior. > Then that behavior could be changed in the next *major* release, since > some BC behavior changes are to be expected then. > As a matter of fact, I've created a rough patch, not to lobby against the ability to decrement_string() per se, but to move string logic to where it belongs; inside ext/standard/string.c The branch differences can be found here: https://github.com/datibbaw/php-src/compare/master...inc-dec-patch Basically it makes the `$x++` or `++$x` work as if you types `$x += 1` or `$x = $x + 1` (except for arrays, currently) So: ++false becomes int(1), --false becomes int(-1) ++true becomes int(2), --true becomes int(0) ++null becomes int(1), --null becomes int(-1) ++"123a" becomes "123b" but with a notice that string increment is deprecated It would introduce the following two string functions, both return a new value (i.e. pass by value): * str_inc($str) * str_dec($str) E.g.: for ($x = "a"; $x < "g"; $x = str_inc($x)); This could be a nice change for the next major version, e.g. (5next).0 > >> >> >>> >>> --Kris >>> >> >> >> >> -- >> -- >> Tjerk >> > > -- -- Tjerk --089e0160caaeaaeb2f04ed69f486--