Is it ok to use ...

Discussion in 'PHP' started by stephan2307, Nov 22, 2010.

  1. #1
    Hi,

    is it ok to use GLOBALS?

    example

    
    
    $var = 'something';
    
    function echoSomething() {
      echo $GLOBALS['var'];
    }
    
    
    PHP:
     
    stephan2307, Nov 22, 2010 IP
  2. sponsorlist

    sponsorlist Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't see a problem with using globals if the code is relatively simple and you can have things under control. But with big and more complex programs it's not usually recommended in most programming languages. See http://en.wikipedia.org/wiki/Global_variable
     
    sponsorlist, Nov 22, 2010 IP
  3. xpertdev

    xpertdev Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it will not create an error but it is not recommended to use in that way.
     
    xpertdev, Nov 22, 2010 IP