Welcome Guest, Not a member yet? Register   Sign In
Variable scope and functions in view
#1

[eluser]Leo78[/eluser]
Hey,

First of all, I know that the following thing it's unacceptable, but I don't have any choice, so don't tell me about it.

I tried to write this simple thing in the view (taken from PHP.net just for the example):

Code:
// view_test.php
<?php
$a = 1;
$b = 2;

function Sum()
{
    global $a, $b;

    $b = $a + $b;
}

Sum();
echo $b;
?>

The controller is simple too:

Code:
class Draw extends MY_Controller {

    function test()
    { $this->load->view('view_test'); }
}

The result should be $b = 3, but $b = 2 and it doesn't refer to the `global` attitude, why does it happen and what can I do to get it works?

Thank you!


Messages In This Thread
Variable scope and functions in view - by El Forum - 10-20-2012, 12:36 AM
Variable scope and functions in view - by El Forum - 10-20-2012, 01:02 AM
Variable scope and functions in view - by El Forum - 10-20-2012, 01:06 AM
Variable scope and functions in view - by El Forum - 10-20-2012, 01:55 AM
Variable scope and functions in view - by El Forum - 10-20-2012, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB