$foo++ becoming 1 when $foo is undefined is not intuitive to me. To take a very trivial example, that behaviour causes “for ($i = 0; $i < 10; $I++) {}” to loop indefinitely.
> On Aug 28, 2019, at 6:52 PM, Stanislav Malyshev <smalys...@gmail.com> wrote: > > Hi! > >> This is where I think PHP may have broken us a little. > > I think it's in no way "broken" to be able to easily match expectations, > like $foo++ always do what you meant without clunky boilerplate. > Also, if you think PHP is the only language I program in daily (and I > mean every day, except some weekends and vacations maybe) you're wrong > :) I have something to compare to, so what I say some things are easier > in PHP that's because I actually compared. > >> I just asked a few non-PHP developers here what they expect "(function >> () { $a++; })()" to do, and they agreed it would be some sort of error. >> Got the same answer for "(function () { $a->bar = 5; })() ". > > I see absolutely no reason for it. Maybe if you're a Java programmer who > never saw non-statically-typed non-B&D language - but that's not a > virtue we should be striving to emulate. If we have a tool that already > does things better and some people don't even know such tools are > possible, we should educate them, not break our tools so it would be > more comfortable fit to their experience. > >> Indeed, anyone who's used another C-like language (JS, TS, Java, C# etc) >> is used to these things being errors, so it can be disorientating to see > > I don't think having things just work instead of usual boilerplate that > you have to declare everything upfront and repeat even obvious things > numerous times is "disorienting" in any way. If you check how languages > that are alive evolve (like Java or C++, C is mostly fossilized these > days), even strict ones, you see they support more and more intuitive > approaches - like auto variables for example - which make things easier. > Because human should spend time thinking, not figuring out how to > satisfy a dumb compiler. That's the direction we should be moving to. > Not adding more errors and boilerplate in clear cases like $foo++. > > -- > Stas Malyshev > smalys...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php