While researching for this suggestion I found this rfc proposal regarding
ifsetor() ( http://wiki.php.net/rfc/ifsetor?s[]=issethttp://wiki.php.net/rfc/ifsetor?s%5B%5D=isset)
and it's rejection point was that it was currently not possible (
http://marc.info/?l=php-internals&m=108931281901389&w=2 )
But would it be possible to check for a value of a variable if it is set?
Since I often do (and see others do)
if(isset($_GET["foo"]) && $_GET["foo"] == "bar")
or even worse
if((isset($_GET["foo"]) && $_GET["foo"] == "bar") || (isset($_GET["baz"]) &&
$_GET["baz"] == "bat"))
to be able to do something like this
if(isset($_GET["foo"]) == "bar")
or
if(isset($_GET["foo"]) == "bar" || isset($_GET["baz"]) == "bat")
That isset (or some other language construct) would return the variable if
it were set and false if it was not.
Thanks for your time, i know this has probably been talked to death in one
form or other.
Ólafur Waage
olafurw@gmail.com
Regarding ifsetor, what's wrong with just using this:
isset($myvar) OR $myvar = 'i am set';
It works in just the same way and has no problems. I agree it would be
great though if there could be a function to retrieve a variable's
value if it exists, without throwing an error if it doesn't exist. I'm
not sure if isset would be appropriate though.
Lewis.
2009/5/12 Ólafur Waage olafurw@gmail.com:
While researching for this suggestion I found this rfc proposal regarding
ifsetor() ( http://wiki.php.net/rfc/ifsetor?s[]=issethttp://wiki.php.net/rfc/ifsetor?s%5B%5D=isset)
and it's rejection point was that it was currently not possible (
http://marc.info/?l=php-internals&m=108931281901389&w=2 )But would it be possible to check for a value of a variable if it is set?
Since I often do (and see others do)
if(isset($_GET["foo"]) && $_GET["foo"] == "bar")
or even worse
if((isset($_GET["foo"]) && $_GET["foo"] == "bar") || (isset($_GET["baz"]) &&
$_GET["baz"] == "bat"))to be able to do something like this
if(isset($_GET["foo"]) == "bar")
or
if(isset($_GET["foo"]) == "bar" || isset($_GET["baz"]) == "bat")That isset (or some other language construct) would return the variable if
it were set and false if it was not.Thanks for your time, i know this has probably been talked to death in one
form or other.Ólafur Waage
olafurw@gmail.com
Regarding ifsetor, what's wrong with just using this:
isset($myvar) OR $myvar = 'i am set';
It works in just the same way and has no problems. I agree it would be
great though if there could be a function to retrieve a variable's
value if it exists, without throwing an error if it doesn't exist. I'm
not sure if isset would be appropriate though.Lewis.
mixed value_of( $variable [, $defaultValue=null] );
<?php
if( value_of( $_GET['action'] ) == 'edit' )
{
// ...
}
switch( value_of( $_GET['action'], 'details' ) )
{
case 'details': ...
}
?>
Cheers,
Rob.
http://www.interjinn.com
Application and Templating Framework for PHP
On Tue, May 12, 2009 at 5:39 PM, Robert Cummings robert@interjinn.comwrote:
Regarding ifsetor, what's wrong with just using this:
isset($myvar) OR $myvar = 'i am set';
It works in just the same way and has no problems. I agree it would be
great though if there could be a function to retrieve a variable's
value if it exists, without throwing an error if it doesn't exist. I'm
not sure if isset would be appropriate though.Lewis.
mixed value_of( $variable [, $defaultValue=null] );
<?php
if( value_of( $_GET['action'] ) == 'edit' )
{
// ...
}switch( value_of( $_GET['action'], 'details' ) )
{
case 'details': ...
}?>
Cheers,
Rob.http://www.interjinn.com
Application and Templating Framework for PHP
Will this run without notices if the value you are passing to the function
isnt set?
Olafur
On Tue, May 12, 2009 at 5:39 PM, Robert Cummings robert@interjinn.comwrote:
Regarding ifsetor, what's wrong with just using this:
isset($myvar) OR $myvar = 'i am set';
It works in just the same way and has no problems. I agree it would be
great though if there could be a function to retrieve a variable's
value if it exists, without throwing an error if it doesn't exist. I'm
not sure if isset would be appropriate though.Lewis.
mixed value_of( $variable [, $defaultValue=null] );
<?php
if( value_of( $_GET['action'] ) == 'edit' )
{
// ...
}switch( value_of( $_GET['action'], 'details' ) )
{
case 'details': ...
}?>
Cheers,
Rob.http://www.interjinn.com
Application and Templating Framework for PHPWill this run without notices if the value you are passing to the function
isnt set?
No, I was suggesting a format for the desired functionality (I should
have been more clear). IMHO the above would be the perfect solution if
it worked in the same manner as isset() (i.e. doesn't generate notices).
Cheers,
Rob.
http://www.interjinn.com
Application and Templating Framework for PHP
-----Original Message-----
From: Ólafur Waage [mailto:olafurw@gmail.com]
Sent: 12 May 2009 17:35
To: internals@lists.php.net
Subject: [PHP-DEV] The constant use of isset()While researching for this suggestion I found this rfc
proposal regarding
ifsetor() (
http://wiki.php.net/rfc/ifsetor?s[]=isset<http://wiki.php.net/
rfc/ifsetor?s%5B%5D=isset>)
and it's rejection point was that it was currently not possible (
http://marc.info/?l=php-internals&m=108931281901389&w=2 )But would it be possible to check for a value of a variable
if it is set?Since I often do (and see others do)
if(isset($_GET["foo"]) && $_GET["foo"] == "bar") or even worse
if((isset($_GET["foo"]) && $_GET["foo"] == "bar") ||
(isset($_GET["baz"]) && $_GET["baz"] == "bat"))to be able to do something like this
if(isset($_GET["foo"]) == "bar")
or
if(isset($_GET["foo"]) == "bar" || isset($_GET["baz"]) == "bat")That isset (or some other language construct) would return
the variable if it were set and false if it was not.Thanks for your time, i know this has probably been talked to
death in one form or other.Ólafur Waage
olafurw@gmail.com
Use array_merge to provide default values...
$get = array_merge($_GET, array('foo' => 'bar', 'baz' => 'bat));
If ($get['foo'] == 'bar' || $get['baz'] == 'bat')
Jared