Create a web app that should create an IP tunnel for clients. For that I need to use CULRL library so I can freely read and edit our JSON file with Client data.
One of the functions that I need to create is createTunnel. I use several parameters in this function – 7 to be precise. Something didn’t work out though. I checked those variables using echo before the function (those are global ones) and the values are correct. Then I’ve used ech with same variables inside the function. And suddenly the values are mixed up.
so i.e.:
$a = $c; $b = $e , $c = $d
etc…
the snippet of the main code:
echo "<br> checking values outside the function: <br>";
echo "rport token: $RPORT_TOKEN <br>";
echo "<br> tunel: <br>";
var_dump($tunnelInfo);
echo "<br><br><br>";
echo "<br>" . "api: " . "$RPORT_API" . "<br>";
echo "opts: " . "$RPORT_OPTS" . "<br>";
echo "q : " . "$_q" . "<br>";
echo "base: " . "$RPORT_BASE" . "<br>";
echo "admin: " . "$RPORT_ADMIN" . "<br>";
echo "token: " . "$RPORT_TOKEN" . "<br>";
$newTunnel = createTunnel ($tunnelInfo, $RPORT_BASE, $_q, $RPORT_API, $RPORT_ADMIN, $RPORT_TOKEN, $RPORT_OPTS);
echo "<br>" . "create Tunnel debug" . "<br>";
echo "<pre>";
var_dump($newTunnel);
echo "</pre>";
}
In the main code the output is correct. $RPORT_ADMIN shows correct admin name, $RPORT_TOKEN gives ouot the correct password etc. As you can see the valuables are checked before the function.
Here is how the function looks like inside the function:
function createTunnel($tunnelInfo, $RPORT_BASE, $_q, $RPORT_API, $RPORT_ADMIN, $RPORT_TOKEN, $RPORT_OPTS)
{
echo "<br> tunel: <br>";
var_dump($tunnelInfo);
echo "<br><br><br>";
echo "<br>" . "api: " . "$RPORT_API" . "<br>";
echo "opts: " . "$RPORT_OPTS" . "<br>";
echo "q : " . "$_q" . "<br>";
echo "base: " . "$RPORT_BASE" . "<br>";
echo "admin: " . "$RPORT_ADMIN" . "<br>";
echo "token: " . "$RPORT_TOKEN" . "<br>";
$tunnelInfo is a decoded JSON table.
Here for example:
echo "<br>" . "api: " . "$RPORT_API" . "<br>";
Output is
“api: $RPORT_BASE
“opts: $RPORT_ADMIN”
etc.
When I change the order of the parameters in the function, i.e.:
function createTunnel($tunnelInfo, $RPORT_API, $$RPORT_BASE, $RPORT_ADMIN, $RPORT_OPTS, $RPORT_TOKEN, $RPORT_OPTS)
The values are once again mixed, different order but completely random. Never correct.
I haven’t noticed any pattern.
I expect that the values of the variables are as I’ve declared them.
I haven’t changed anywhere the values of the variables. How is that possible?
7