1

I have a stupid problem because I've got calls to this function all over my code base. Sometimes my code is run on PHP 5, 7 and who knows what else.

I need a way to resolve this deprecated code issue, hopefully without rewriting every call to the existing function.

It should be noted that the pass by reference is the main issue I'm struggling with right now.

Is it possible?

    function getSetting(& $var, $default=0) {
        if (isset($var)) {
            return $var;
        }
        return $default;
    }

Remember that sometimes a plain variable is passed in as the first parameter. Other times an array with non-existing index value is passed (and of course, sometimes the array index exists and has a value).

... the original reason I chose pass by reference so the function can look at the outer value.

Byron
  • 21
  • 4
  • I ended up replacing the function entirely with is_set and array_key_exists calls. Not at all what I prefer because it thrashed my entire code base, but it works. – Byron Jul 28 '19 at 07:59

1 Answers1

0

work arounds

Version test for the function

if (version_compare(phpversion(), '7.0', '<')) 
{
    function getSetting() { echo "Old function"; }
} 
else 
{
    function getSetting() { echo "New function"; }
}

its not great but works or you could have 2 functions files and include them based on version.

IcePops
  • 11
  • 4
  • I appreciate the thought. I understand how the PHP 5.x version works. I'm not certain how to write the PHP 7.x version of that function. Any thoughts? At this point, any solution that works for both is a good one, even if it isn't elegant. – Byron Nov 11 '18 at 16:39