For class variables, yes. For function parameters, yes. In the global scope,
no, as it makes little sense.
If you're talking about GET and PUT variables, you can write a little
function that does that. I use a function I call "StickyVariable" in a lot
of situations where state values are required:
function StickyVariable($name, $default = null) {
if(isset($_REQUEST[$name])) {
$GLOBALS[$name] = $_SESSION[$name] = $_REQUEST[$name];
}
else if(isset($_SESSION[$name])) {
$GLOBALS[$name] = $_SESSION[$name];
}
else {
$GLOBALS[$name] = $default;
}
}
....
StickyVariable("sort_type", SORT_BY_DATE);
StickyVariable("sort_dir", SORT_ASCENING);
Uzytkownik "lurisia" <he***@hello.com> napisal w wiadomosci
news:de********************************@4ax.com...
Does php provide a built in way to use a variable's current value if
that variable is already set but to use a default value otherwise.
That is, a more compact syntax for:
$some_var = isset("$some_var") ? $some_var : "default value";
Thanks,
lurisia