# what happened to that new isset() like language

- Thread: https://externals.io/message/19801
- Original archive: https://news-web.php.net/php.internals/19801
- Started by James Crumpton on 2005-10-29T00:44:36+00:00
- Messages: 22
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #19801 — James Crumpton — 2005-10-29T00:44:36+00:00

URL: https://externals.io/message/19801#19801

Andi Gutmans wrote:
 > I don't think it's a matter of giving the engine a try. I think we first need
 > to make a decision what the best way to go is and then we can discuss
 > implementation if/what is possible. Once 5.0.0 is out I'm going to have more
 > time look into this.

What's the word on this?

Some of the names given were:
issetor
ifsetor
ifset
ifnull
coalesce

I'm actually kind of partial to:

$a = $foo || $bar;
$a = $foo || $bar || $xyz || $etc;

Or better yet (or maybe in addition too):

$a['foo'] ||= 'bar'; // if set do nothing, otherwise assign 'bar'


-james

---

## #19802 — Sebastian — 2005-10-29T01:48:18+00:00

URL: https://externals.io/message/19801#19802 · In reply to: #19801

Wow, it'll be just like perl! this is so great.


> Andi Gutmans wrote:
> > […]
>
> What's the word on this?
>
> Some of the names given were:
> issetor
> ifsetor
> ifset
> ifnull
> coalesce
>
> I'm actually kind of partial to:
>
> $a = $foo || $bar;
> $a = $foo || $bar || $xyz || $etc;
>
> Or better yet (or maybe in addition too):
>
> $a['foo'] ||= 'bar'; // if set do nothing, otherwise assign 'bar'
>
>
> -james
>
> --
> 
> 
>
>


--



-------------
buddhahead@gmail.com

---

## #19804 — James Crumpton — 2005-10-29T02:34:19+00:00

URL: https://externals.io/message/19801#19804

Evaluating an idea based on it's syntactic similarities to other languages is 
complete and utter nonsense. It has nothing to with being like language Xyz. It 
has to do with familiarity to language constructs. One already understands the 
idea of 'this || that'. It's certainly doesn't take a stretch of the imagination 
to assume that at least a beginner programmer will believe that '$a = $this || 
$that;' would return one of the two values (as opposed to the boolean it now 
returns). The point is, I don't have to look up in the documentation what '||' 
means, or '? :' means... or (hypothetically) what '||=' means. They are concepts 
that are easy to understand and, more importantly, easy to remember.

If this concept is turned into a function, it'll be another in a long list of 
functions for PHP that are difficult to remember for either their name (issetor? 
ifsetor? ifset?) or the order of arguments thereof (ie. array and string 
handling functions).


Sebastian wrote:
> Wow, it'll be just like perl! this is so great.
> 
> 
> > […]
> 
> 
> --
> 
> 
> 
> -------------
> buddhahead@gmail.com

---

## #19807 — Greg Beaver — 2005-10-29T05:32:08+00:00

URL: https://externals.io/message/19801#19807 · In reply to: #19804

James Crumpton wrote:
> Evaluating an idea based on it's syntactic similarities to other
> languages is complete and utter nonsense. It has nothing to with being
> like language Xyz. It has to do with familiarity to language constructs.
> One already understands the idea of 'this || that'. It's certainly

I'll throw the water on this one:

<?php
$c = 0;
$a = 1;
var_dump($c || $a);
?>

With the existing PHP, this script results in:

bool(true)

With your proposed change because it would return the first non-null set
variable, it will instead output:

int(0)

Changing true into false consitutes a rather severe BC break :).

Greg

---

## #19820 — James Crumpton — 2005-10-29T20:27:33+00:00

URL: https://externals.io/message/19801#19820 · In reply to: #19807

A good point certainly... I suppose it could continue to follow the 
current form, evaluating $c as false and return int(1) instead of 
bool(true). Though that would probably diminish it's utility for 'if set 
or'. And there would be a BC break for those doing:

$a = $b || $c;

if ($a === true) {
}

But anyone doing that should probably have their head examined.

Anyway...

Regardless of what can be said about changing the behavior of '||', the 
same isn't true for '||=', as it has no precedence in PHP.

-james

Greg Beaver wrote:

>James Crumpton wrote:
>  
>
> > […]
>
>I'll throw the water on this one:
>
><?php
>$c = 0;
>$a = 1;
>var_dump($c || $a);
>?>
>
>With the existing PHP, this script results in:
>
>bool(true)
>
>With your proposed change because it would return the first non-null set
>variable, it will instead output:
>
>int(0)
>
>Changing true into false consitutes a rather severe BC break :).
>
>Greg

---

## #19822 — James Crumpton — 2005-10-29T20:31:03+00:00

URL: https://externals.io/message/19801#19822 · In reply to: #19807

A good point certainly... I suppose it could continue to follow the
current form, evaluating $c as false and return int(1) instead of
bool(true). Though that would probably diminish it's utility for 'if set
or'. And there would be a BC break for those doing:

$a = $b || $c;

if ($a === true) {
}

But anyone doing that should probably have their head examined.

Anyway...

Regardless of what can be said about changing the behavior of '||', the
same isn't true for '||=', as it has no precedence in PHP.

-james

Greg Beaver wrote:

>James Crumpton wrote:
>  
>
> > […]
>
>I'll throw the water on this one:
>
><?php
>$c = 0;
>$a = 1;
>var_dump($c || $a);
>?>
>
>With the existing PHP, this script results in:
>
>bool(true)
>
>With your proposed change because it would return the first non-null set
>variable, it will instead output:
>
>int(0)
>
>Changing true into false consitutes a rather severe BC break :).
>
>Greg

---

## #19823 — Matthew C. Kavanagh — 2005-10-29T20:41:36+00:00

URL: https://externals.io/message/19801#19823 · In reply to: #19820

However, in terms of precedents, there are the combined assignment
operators such as &=, +=, .=, and so on. They would suggest that

$a ||= $b;

should be equivalent to

$a = $a || $b;

So I don't think ||= in the suggested usage is intuitive. And adding
strange automagical meanings to $a = $a || $b || $c; (and so forth)
shouldn't even be discussed by sane people ;)


> Regardless of what can be said about changing the behavior of '||', the 
> same isn't true for '||=', as it has no precedence in PHP.

---

## #19824 — Sara Golemon — 2005-10-29T21:07:37+00:00

URL: https://externals.io/message/19801#19824 · In reply to: #19807

> > […]
> 
> I'll throw the water on this one:
> 
> <?php
> $c = 0;
> $a = 1;
> var_dump($c || $a);
> ?>
> 
> Changing true into false consitutes a rather severe BC break :).
> 
How about |||  and |||= ?

---

## #19825 — Jasper Bryant-Greene — 2005-10-29T21:34:52+00:00

URL: https://externals.io/message/19801#19825 · In reply to: #19824

> > […]
> How about |||  and |||= ?
> 

How about ~ and ~= ? Shorter to type.

I know that in logic it can mean NOT, but I think nearly all PHP
programmers would know that ! serves that purpose in PHP.

-- 
Jasper Bryant-Greene
General Manager
Album Limited

e: jasper@album.co.nz
w: http://www.album.co.nz/
b: http://jbg.name/
p: 0800 4 ALBUM (0800 425 286) or +64 21 232 3303
a: PO Box 579, Christchurch 8015, New Zealand

---

## #19826 — Marcus Boerger — 2005-10-29T21:39:53+00:00

URL: https://externals.io/message/19801#19826 · In reply to: #19825

Hello Jasper,

Saturday, October 29, 2005, 11:34:52 PM, you wrote:

> 
> > […]

> How about ~ and ~= ? Shorter to type.

> I know that in logic it can mean NOT, but I think nearly all PHP
> programmers would know that ! serves that purpose in PHP.

And guess what we have that ~ operator already: php -r 'var_dump(~0);'
RTFM :-)

Best regards,
 Marcus

---

## #19827 — Greg Beaver — 2005-10-29T21:56:16+00:00

URL: https://externals.io/message/19801#19827 · In reply to: #19824

Sara Golemon wrote:
> > […]
> How about |||  and |||= ?

I don't think the meaning of this operator is obvious.  Right now, the
only operators whose meaning are not immediately obvious (in my eyes) are:

@ - error suppression
& - make reference in some cases, bitwise and in others
^ - bitwise xor but what are you gonna do :)

For an operation as complicated as "use the first variable that exists"
I would be most comfortable with:

$d = first-existing: $a, $b, $c;

This way, no conflict with functions (parse error in previous php
versions), and it is extremely clear.  The parser would look for

T_FIRSTEXISTING ':' existing_varlist

in the expression section, and of course defining existing_varlist as:

existing_varlist:
	variable
	|	existing_varlist ',' variable
;

Greg

---

## #19828 — Sebastian — 2005-10-29T22:43:20+00:00

URL: https://externals.io/message/19801#19828 · In reply to: #19827

I still think // and //= would be the most reasonable. They involve
the least amount of syntax and // looks similar to ||


> Sara Golemon wrote:
> > […]
>
> I don't think the meaning of this operator is obvious.  Right now, the
> only operators whose meaning are not immediately obvious (in my eyes) are:
>
> @ - error suppression
> & - make reference in some cases, bitwise and in others
> ^ - bitwise xor but what are you gonna do :)
>
> For an operation as complicated as "use the first variable that exists"
> I would be most comfortable with:
>
> $d = first-existing: $a, $b, $c;
>
> This way, no conflict with functions (parse error in previous php
> versions), and it is extremely clear.  The parser would look for
>
> T_FIRSTEXISTING ':' existing_varlist
>
> in the expression section, and of course defining existing_varlist as:
>
> existing_varlist:
>         variable
>         |       existing_varlist ',' variable
> ;
>
> Greg
>
> --
> 
> 
>
>


--



-------------
buddhahead@gmail.com

---

## #19829 — Rasmus Lerdorf — 2005-10-29T22:47:03+00:00

URL: https://externals.io/message/19801#19829 · In reply to: #19828

Sebastian wrote:
> I still think // and //= would be the most reasonable. They involve
> the least amount of syntax and // looks similar to ||

// is a comment.  Why don't you guys at least take a peek at the grammar 
  before suggesting stuff.

-Rasmus

---

## #19832 — alpha@rrs@Nico Edtinger — 2005-10-29T22:57:26+00:00

URL: https://externals.io/message/19801#19832 · In reply to: #19828

Hi!

If you want something similar why not something that's similar to the  
currently used $x = isset($x) ? $x :'x';. I don't think PHP has  
something that can be written as ?? currently and it would be similar  
to the current expression: $x = $x ?? 'x'; or $x ??= 'x'; Or if it  
should be a single char § chould be used - altough it looks ugly.

I'd still prefer a named operator like the new instanceof. It's much  
easier to read, can be found in the manual and it's meaning is clear  
to none-PHP programmers.

b4n, nico

Am 30.10.2005 um 00:43 schrieb Sebastian:

> I still think // and //= would be the most reasonable. They involve
> the least amount of syntax and // looks similar to ||

---

## #19833 — Sebastian — 2005-10-29T22:58:52+00:00

URL: https://externals.io/message/19801#19833 · In reply to: #19827

Given that // is not acceptable, as others sarcastically reminded me,
and that this introduces new sytax, I think it might be best just to
add more functions. I don't think something like

> $d = first-existing: $a, $b, $c;

is any better than first_existing($a, $b, $c), and the former happens
at the expensive of inconsistency and a higher learning curve.

---

## #19834 — Arpad Ray — 2005-10-29T23:02:23+00:00

URL: https://externals.io/message/19801#19834 · In reply to: #19829

For the assign-if-not-set operator, I like the idea of:

$foo ?= 'bar';

? implies a condition, and the = immediately following will raise a parse 
error in older versions.

There's admittedly potential for confusion with the ternary operator, but 
since that's most commonly used for conditional assignment I think the 
association isn't all negative.

Arpad

---

## #19835 — Sebastian — 2005-10-29T23:13:09+00:00

URL: https://externals.io/message/19801#19835 · In reply to: #19834

But what about the use of ? as an infix operator? that wouldn't work
out so well because of the ternary ?:


> For the assign-if-not-set operator, I like the idea of:
>
> $foo ?= 'bar';
>
> ? implies a condition, and the = immediately following will raise a parse
> error in older versions.
>
> There's admittedly potential for confusion with the ternary operator, but
> since that's most commonly used for conditional assignment I think the
> association isn't all negative.
>
> Arpad
>
> --
> 
> 
>
>


--



-------------
buddhahead@gmail.com

---

## #19836 — Edin Kadribasic — 2005-10-29T23:18:53+00:00

URL: https://externals.io/message/19801#19836 · In reply to: #19802

If we're going to add a new language construct I believe that it should 
be readable and not some perl-like thingie. SQL has coalesce() functions 
which returns returns first non-null argument of any number of 
arguments. PHP version could return a first set argument:

$lang = coalesce($_COOKIE['lang'], $user_settings['lang'], 'en');

It shouldn't be too difficult to tell what this one does.

Edin

Sebastian wrote:
> Wow, it'll be just like perl! this is so great.
> 
> 
> > […]
> 
> 
> --
> 
> 
> 
> -------------
> buddhahead@gmail.com

---

## #19837 — Greg Beaver — 2005-10-29T23:22:00+00:00

URL: https://externals.io/message/19801#19837 · In reply to: #19833

Sebastian wrote:
> Given that // is not acceptable, as others sarcastically reminded me,
> and that this introduces new sytax, I think it might be best just to
> add more functions. I don't think something like
> 
> 
> > […]
> 
> 
> is any better than first_existing($a, $b, $c), and the former happens
> at the expensive of inconsistency and a higher learning curve.

au contraire.  The first happens without a name collision with any
user-space functions.

Greg

---

## #19838 — Arpad Ray — 2005-10-29T23:33:23+00:00

URL: https://externals.io/message/19801#19838 · In reply to: #19835

Sebastian wrote:
> But what about the use of ? as an infix operator? that wouldn't work
> out so well because of the ternary ?:
>

Right, which is why I didn't suggest that.

I think Greg's idea of first-existing: is an interesting one (and by the sound 
of it the most robust).

Personally I'd like coalesce() because of the SQL link, but firstset() also 
appeals to me, being pretty self-explanatory and strongly reminiscent of 
isset().

---

## #19839 — Marcus Boerger — 2005-10-29T23:52:37+00:00

URL: https://externals.io/message/19801#19839 · In reply to: #19836

Hello Edin,

 on the other hand it is not doable....not without a major slowdown.
Thus the idea of ifsetor($var, <expression>).

Why the hell do we need to discuss this over and over again?
The only way is this version. Be it with some cryptic operator like
'?:' or some function name like 'ifsetor'. Either way our internals
and the use of compiler compiler tools do not allow other stuff.
And speaking of '?:' we turned that down because it does suggest
'$a ? $a : <expr>' which is different from the functionality we
actually want: 'isset($a) ? $a : <expr>'. And actually 'ifsetor'
was only turned down because someone very very hard tried to find a
way to turn it down and could only come up with saying its name is
bad. Which i obviously absolutley disagree since its name is
perfectly clear and does not lead to confusion. Becuase it suggests
something like "IF something isSET than take it OR use the other".

regards
marcus

Sunday, October 30, 2005, 1:18:53 AM, you wrote:

> If we're going to add a new language construct I believe that it should 
> be readable and not some perl-like thingie. SQL has coalesce() functions 
> which returns returns first non-null argument of any number of 
> arguments. PHP version could return a first set argument:

> $lang = coalesce($_COOKIE['lang'], $user_settings['lang'], 'en');

> It shouldn't be too difficult to tell what this one does.

> Edin

> Sebastian wrote:
> > […]




Best regards,
 Marcus

---

## #19851 — Jani Taskinen — 2005-10-30T19:23:58+00:00

URL: https://externals.io/message/19801#19851 · In reply to: #19824

> How about |||  and |||= ?

     How about a good ol' beating with a large trout? :)

     --Jani
