Re: [RFC] Path to Saner Increment/Decrement operators

From: Date: Thu, 19 Jan 2023 10:47:23 +0000
Subject: Re: [RFC] Path to Saner Increment/Decrement operators
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-119348@lists.php.net to get a copy of this message
On 19.01.2023 at 01:23, Mark Baker wrote: > However, the ++ and -- are the "Increment" and "Decrement" operators, > not the Add1 and Subtract1 operators; while they behave in that way when > used with variables containing numeric values, they are special > operators and not simply a syntactic sugar for +=1 and -=1. As long as > their behaviour is consistent, and definition of what "Increment" and > "Decrement" mean is clearly defined for different datatypes, then I feel > that the PERL-style alpha string increment has enough valid use cases to > justify itself. I understand your point, but also understand why increment/decrement operations can be seen as adding/subtracting 1 (the current documentation is actually pretty close to that interpretation). I'm not sure which interpretation I'd prefer. > We might also discuss consistency of datatype changes when these > operators are used. > > $a = PHP_INT_MAX; > > ++$a; > > or > > $a = '10'; > > ++$a; > > both change the datatype of $a; which isn't documented behaviour either. Well, that is the usual type juggling, but is indeed not properly document, from what I can tell (the "type juggling" page doesn't mention increment/decrement, and the "incrementing/decrementing operators" page doesn't mention the type juggling). -- Christoph M. Becker

« previous php.internals (#119348) next »