> If we want PHP to be as easy as possible then $nullref->bar(), > $foo->someUndefined(), > new UndefinedClass etc shouldn’t be exceptions either - they can just be > notices.
That's very different. Note that this code doesn't even generate a notice: $x = null; var_dump($x+1); I'm joining the thread to point out another way to avoid the notice in hopes that this way doesn't get deprecated or somesuch: $temp =& $never_defined; // No notice :) $temp++; // Happily becomes 1 if $never_defined wasn't defined unset($temp); // so we don't unintentionally make more changes with $temp later Our code predates "??" and we use the above boilerplate in many, many places, but it isn't boilerplate enough to easily search and replace. - Todd > On Aug 28, 2019, at 4:01 PM, Stanislav Malyshev <smalys...@gmail.com> wrote: > > Hi! > >> Javascript has treated undefined variables as a catchable exceptions since >> (I think?) forever. > > Which seems to be why I open a random Javascript file in our codebase > and see this: > > var wikibase = wikibase || {}; > wikibase.queryService = wikibase.queryService || {}; > wikibase.queryService.ui = wikibase.queryService.ui || {}; > wikibase.queryService.ui.toolbar = wikibase.queryService.toolbar || {}; > > wikibase.queryService.ui.toolbar.Actionbar = ... > > (not my code but I've seen it a lot) > IMHO, this is language getting in a way and people writing boilerplate > to avoid "service" that is not actually needed. > >> much work. This means its developers often don't improve much either, which > > I don't think PHP should be a language that "builds character" by > forcing people to do more work than it's necessary for them, in order > for them to "improve". I think it should be as easy as possible, and if > somebody wants to learn how the bits move, one can always pick up a good > book or go to a Coursera course, etc. > > -- > Stas Malyshev > smalys...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php