Re: what happened to that new isset() like language

php.internals

Jason Garber

22 years ago
The original reason that I asked for this functionality was to make it significantly easier to work with E_ALL error reporting. When I say easier, I mean by reducing duplicate code. //This $foo = (integer) ifsetor($_POST['foo'], 0); //Instead of $foo = (integer) (isset($_POST['foo']) ? $_POST['foo'] : 0); It was also to be useful for accessing array elements that may or may not be there. I strongly agree with Ramsus that ?: is far to close to the ternary operator and would prove to be *highly* confusing to beginners. Marcus made an excellent point about the 2 versions of the function: 1) $a = ifsetor($b) 2) $a = ifsetor($b, NULL) By the way, I'm not stuck on ifsetor() as a name, but a) the name should be short and clear b) the construct must be called with function like syntax Marc, I must ask, why are you so opposed to the function() syntax? There has been quite a few reasons stated against the operator syntax, but I haven't heard any reason why we should not go with the function() syntax? Sincerely, Jason Garber

Marc Richards

22 years ago
Jason Garber wrote:
> The original reason that I asked for this functionality was to make it > significantly easier to work with E_ALL error reporting. When I say > easier, I mean by reducing duplicate code. > > //This > $foo = (integer) ifsetor($_POST['foo'], 0); > > //Instead of > $foo = (integer) (isset($_POST['foo']) ? $_POST['foo'] : 0); > > It was also to be useful for accessing array elements that may or may > not be there. > > I strongly agree with Ramsus that ?: is far to close to the ternary > operator and would prove to be *highly* confusing to beginners.
I don't think it would be *highly* confusing to someone who has already used a ternary statement. If they haven't then even a ternary statement would be confusing. In either case I think good documentation would be important. I am still on the fence about the asymmetry in that one tests isset() while the other doesn't
> Marcus made an excellent point about the 2 versions of the function: > 1) $a = ifsetor($b) > 2) $a = ifsetor($b, NULL) >
See my response to Marcus' post
> By the way, I'm not stuck on ifsetor() as a name, but > a) the name should be short and clear > b) the construct must be called with function like syntax > > > Marc, > I must ask, why are you so opposed to the function() syntax? There has > been quite a few reasons stated against the operator syntax, but I > haven't heard any reason why we should not go with the function() syntax? >
I am interested in the new construct for the exact same reason, E_ALL development. I am intersted in the ?: operator because it looks alot simpler, especially if you want to chain them together: $user = $_SESSION['user] ?: $_POST['user'] ?: $local_user ?: NULL; I am not even sure if marcus' patch allowed you to nest multiple ifsetor() calls...either way, my main goal is simplicity. I am not just trying to be contentious, I am actually interested in a good solution. Marc

Daniel Crookston

22 years ago
Oh baby, oh baby. I was undecided (and really just didn't care about it either way) but when Marc put it this way (see the bottom line there) I was sold. That's just sexy. -Dan, who perhaps gets a bit *too* into this sort of thing...

Curt Zirzow

22 years ago
* Thus wrote Marc Richards:
> > > Jason Garber wrote: > > > I am interested in the new construct for the exact same reason, E_ALL > development. I am intersted in the ?: operator because it looks alot > simpler, especially if you want to chain them together: > > $user = $_SESSION['user] ?: $_POST['user'] ?: $local_user ?: NULL;
At this point, might as well make the Or operator silence E_NOTICE warnings: $user = $_SESSION['user] Or $_POST['user'] Or $local_user Or NULL; at least it would be readable. The biggest problem I have with using ?: is that down the line we might just have something like: $foo = $bar ?%@*&!: $qaz Inventing operators that consist more than one character can lead to trouble. Curt
-- First, let me assure you that this is not one of those shady pyramid schemes you've been hearing about. No, sir. Our model is the trapezoid!

Jason Garber

22 years ago
Hi Marc, To be honest, I don't care at this point. As long as we have something implemented in 5.1 for allowing PHP users to simplify working in E_ALL error mode. This thing: a) it has to base it's decision on the same logic isset() uses b) it should not evaluate the second part unless it is needed c) it should not be confusing This reminds me of the instanceof keyword. What about using something like that? $foo = $bar setor $baz; If that could be implemented, it may be a way to consider. It would a) be easy to recognize b) be easy to chain them together c) not be confusing d) have a short, concise, CLEAR name Comments? Sincerely, Jason Garber At 7/8/2004 07:48 PM -0400, you wrote: