Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

issue.global

edsonmedina edited this page Dec 11, 2014 · 10 revisions

#Global variables

function foo () 
{
    global $bar;

    // ...
}

##Why is this a testing issue?

  • Global variables can be changed outside of the scope of your function, so its behaviour is unpredictable in a running environment.
  • Unit-tests should test isolated units. Global scope does not fit into that.

##Possible solutions

####Pass the variable as an argument to your function.

function foo ($bar)  

####Get the values from some other source

function foo () 
{
    $bar = $this->assets->get('bar');

    // ...
}
Clone this wiki locally