Jump to content

Should be simple: function return error, what am I missing?


Q695

Recommended Posts

inside function:

echo "<br>random path: $path_rand";
        return $path_rand;

 

outside function:

echo "<p>random path2: $path_rand";

 

$path_rand is echo in the function, but for some reason not being posted outside of the function.  Why?

 

I tried the following simple script:

function test(){
    $i=2;
    return $i;
    }
    test();
    echo "X:$i";
 

 

got back: Notice: Undefined variable: in ______ on line X(echo line)

X:

Should be a global, not a return :shrug:

 

 

bullshit-meter-01_thumb.gif

 

That reply deserves top spot in this site's Hall of Shame.

 

You should NOT use globals. You should pass values to functions then use the value returned by the function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.