Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70624 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25268 invoked from network); 13 Dec 2013 12:01:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2013 12:01:00 -0000 Authentication-Results: pb1.pair.com header.from=kris.craig@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kris.craig@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.173 as permitted sender) X-PHP-List-Original-Sender: kris.craig@gmail.com X-Host-Fingerprint: 209.85.214.173 mail-ob0-f173.google.com Received: from [209.85.214.173] ([209.85.214.173:60998] helo=mail-ob0-f173.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/BE-32587-BF6FAA25 for ; Fri, 13 Dec 2013 07:00:59 -0500 Received: by mail-ob0-f173.google.com with SMTP id gq1so1839740obb.18 for ; Fri, 13 Dec 2013 04:00:56 -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=8Sx4O8gmL1o5KJ5L37SYSr0NKF+i4sj/bnsc7+xtwV0=; b=wmkdsdWDmDc9kCmBQWDHFEe83jhhnaY8KRfmifbx1gaKDf2bHRLaNc3xQcarZrgn7C V9cggdr4U0By8/eJGGpS7PjODnWqP5HBHtIw6Xod55APzwVQdMJCXmf4eUSXy7uD/JZt 0tTY3HDQJjs6oTYQkPU6rnJlzD93WStF/RRj6zkyPgW/OOdOlwPKVBtGUrT5bLqL6PzJ V+73mg494cIrf+diNC14y1TS5lBX31KT6J9oiCmxv6ym3WmabvnnmMGF6VQM6nglNQKg /dHdIyG99/46o05Vch/xkrpLGmzj8x1iqP6Z7QPaDjcx64IcjxPP0XYjwneheXRkv2v3 5aqw== MIME-Version: 1.0 X-Received: by 10.60.44.239 with SMTP id h15mr1451049oem.22.1386936056764; Fri, 13 Dec 2013 04:00:56 -0800 (PST) Received: by 10.182.221.170 with HTTP; Fri, 13 Dec 2013 04:00:56 -0800 (PST) In-Reply-To: References: <52AA1649.2090601@ajf.me> <52AAA1EA.7030106@marc-bennewitz.de> Date: Fri, 13 Dec 2013 04:00:56 -0800 Message-ID: To: Tjerk Meesters Cc: Marc Bennewitz , PHP internals list Content-Type: multipart/alternative; boundary=001a11331e1afd5e3004ed693688 Subject: Re: [PHP-DEV] [PROPOSAL] Alphanumeric decrement From: kris.craig@gmail.com (Kris Craig) --001a11331e1afd5e3004ed693688 Content-Type: text/plain; charset=ISO-8859-1 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. > > >> >> --Kris >> > > > > -- > -- > Tjerk > --001a11331e1afd5e3004ed693688--