# what happened to that new isset() like language

- Thread: https://externals.io/message/11038
- Original archive: https://news-web.php.net/php.internals/11038
- Started by cysgwr_eryri@yahoo.co.uk on 2004-07-09T19:07:53+00:00
- Messages: 3
- 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

---

## #11038 — cysgwr_eryri@yahoo.co.uk — 2004-07-09T19:07:53+00:00

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

Isn't this problem solvable with just a "User Space" function?

<?php

    error_reporting(E_ALL);

    function ifsetor(&$variable, $alternate = NULL){
        if(isset($variable)){
            $tmp = $variable;
            echo('<p>$variable exists.</p>');
        }
        else{
            $tmp = $alternate;
            echo('<p>no $variable here.</p>');
        }
        return $tmp;
    }
    
    // no errors thrown ...

    $nonexistent = ifsetor($nonexistent);
    ifsetor($randomNonexistent);
	
    if($nonexistent !== NULL)
        echo('<p>$nonexistent is NOT NULL</p>');
    else
        echo('<p>$nonexistent is NULL</p>');

?>

Because, as Derick Rethans mentioned, arguments passed by
reference will not trigger the Undefined (variable | index)
Notice at the point of the function call, and also PHP's C++
style default arguments providing the alternate value, surely
the above code would suffice?

Apologies if I've completely misunderstood (with certainty a
non-zero probability)...

Regards,

Cris


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com

---

## #11039 — Sean Coates — 2004-07-09T19:18:33+00:00

URL: https://externals.io/message/11038#11039 · In reply to: #11038

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Cris H wrote:
| Isn't this problem solvable with just a "User Space" function?
[snip]
| Because, as Derick Rethans mentioned, arguments passed by
| reference will not trigger the Undefined (variable | index)
| Notice at the point of the function call, and also PHP's C++
| style default arguments providing the alternate value, surely
| the above code would suffice?
|
| Apologies if I've completely misunderstood (with certainty a
| non-zero probability)...
|

I understand that this is not sufficient because of the following
circumstance:

$var = ifsetor($_GET['test'], foo());

foo() is ALWAYS evaluated with the user-space function you wrote. I
understand that we don't want foo() to be called unless it needs to be
returned (ie, we want to be able to short circuit the parameters)?

Now, maybe _I'M_ misunderstanding? (-: I don't have much knowledge of
internals, but is this even POSSIBLE as a function call, and not as an
operator?

S
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFA7u+JWppknrQMxQIRAg1KAJ4tApnlVxsD/2Sc/3HubJtzFsp9tQCglqXZ
93qdums+B43W1Rpgjp1hLMg=
=91eL
-----END PGP SIGNATURE

---

## #11040 — Todd Ruth — 2004-07-09T19:23:58+00:00

URL: https://externals.io/message/11038#11040 · In reply to: #11038

That would satisfy some of the requested feature, but try
calling ifsetor($my_array['bad key'], functionWithSideEffects()).
Marcus has repeatedly mentioned that the requested feature is
hard (bordering on impossible) to implement, but in the requested
feature (if I understand it (and it is what I would ask for too :) )),
there would be no error for using a key that isn't in the array,
there would be no side effect of creating a key in the array, and
if the $my_array['bad key'] actually did happen to be non-NULL,
the function with the side effects wouldn't get called.

That would be really handy, especially if it could take a variable
number of arguments.  Using a standard name like coalesce would
be nice.

BTW, I have no weight around here; just thought I could help
clarify, having following this thread with interest...

- Todd


> Isn't this problem solvable with just a "User Space" function?
> 
> <?php
> 
>     error_reporting(E_ALL);
> 
>     function ifsetor(&$variable, $alternate = NULL){
>         if(isset($variable)){
>             $tmp = $variable;
>             echo('<p>$variable exists.</p>');
>         }
>         else{
>             $tmp = $alternate;
>             echo('<p>no $variable here.</p>');
>         }
>         return $tmp;
>     }
>     
>     // no errors thrown ...
> 
>     $nonexistent = ifsetor($nonexistent);
>     ifsetor($randomNonexistent);
> 	
>     if($nonexistent !== NULL)
>         echo('<p>$nonexistent is NOT NULL</p>');
>     else
>         echo('<p>$nonexistent is NULL</p>');
> 
> ?>
> 
> Because, as Derick Rethans mentioned, arguments passed by
> reference will not trigger the Undefined (variable | index)
> Notice at the point of the function call, and also PHP's C++
> style default arguments providing the alternate value, surely
> the above code would suffice?
> 
> Apologies if I've completely misunderstood (with certainty a
> non-zero probability)...
> 
> Regards,
> 
> Cris
> 
> 
> 	
> 	
> 		
> ___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com
