Howto:Understand Namespaces and Methods: Difference between revisions

Jump to navigation Jump to search
m
Line 26: Line 26:
  house3_bath
  house3_bath


These naming conventions can become awkward pretty quickly.
As you can see, these naming conventions can become awkward and inflexible pretty quickly:
 
<syntaxhighlight lang="php">
      var wp1 = 0;
      var wp1alt = 0;
      var wp1dist = 0;
      var wp1angle = 0;
      var wp1length = 0;
      var wp1id = "";
      var wp1brg = 0;
 
      var wp2 = 0;
      var wp2alt = 0;
      var wp2dist = 0;
      var wp2angle = 0;
      var wp2length = 0;
      var wp2id = "";
      var wp2brg = 0;
 
      var wp3 = 0;
      var wp3alt = 0;
      var wp3dist = 0;
      var wp3angle = 0;
      var wp3length = 0;
      var wp3id = "";
      var wp3brg = 0;
 
      var wp4 = 0;
      var wp4alt = 0;
      var wp4dist = 0;
      var wp4angle = 0;
      var wp4length = 0;
      var wp4id = "";
      var wp4brg = 0;
 
      var wp5 = 0;
      var wp5alt = 0;
      var wp5dist = 0;
      var wp5angle = 0;
      var wp5length = 0;
      var wp5id = "";
      var wp5brg = 0;
</syntaxhighlight>
 


Before namespaces were used, there were only such "global variables", so whenever some piece of code referred to a variable, it was possible to clash with some other similar or even unrelated uses of the variable (imagine a counter variable).
Before namespaces were used, there were only such "global variables", so whenever some piece of code referred to a variable, it was possible to clash with some other similar or even unrelated uses of the variable (imagine a counter variable).

Navigation menu