struggling to figure out why I am getting "null"

Discussion in 'PHP' started by lazerorca, Nov 18, 2014.

  1. #1
    So this is my class file

    ----------------------


    <?php
    
    Class Config {
    
    private static $_config_array = array(
       'dbhost' => 'localhost',
       'dbname' => 'practice',
       'dbuser' => 'root',
       'dbpass' => 'mysql'
       );
    
    public static function get($dbkey) {
       return $_config_array[$dbkey];
    }
    
    }
    
    ?>
    PHP:
    ------------------


    this is where I am trying to sort of debug


    ------------------

    <?php
    
    include 'Config.php';
    
    var_dump(Config::get(dbhost));
    
    ?>
    PHP:
    -------------------

    What I was expecting to get is "localhost", but I am getting NULL. As you can see I am very new to all of this
     
    Last edited by a moderator: Nov 18, 2014
    lazerorca, Nov 18, 2014 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,893
    Likes Received:
    4,553
    Best Answers:
    123
    Trophy Points:
    665
    #2
    you'll kick yourself :)

    public static function get($dbkey) {
       return $this->_config_array[$dbkey];
    }
    PHP:
     
    sarahk, Nov 18, 2014 IP
  3. lazerorca

    lazerorca Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    1
    #3
    oh no... man I am struggling hard with this stuff lol... this is going to be a long process
     
    lazerorca, Nov 18, 2014 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,893
    Likes Received:
    4,553
    Best Answers:
    123
    Trophy Points:
    665
    #4
    it gets easier, I promise!
     
    sarahk, Nov 18, 2014 IP
  5. lazerorca

    lazerorca Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    1
    #5
    any ideas as to why this is telling me that I have an unexpected {

    spl_autoload_register(function ($class) {
    include 'classes/' . $class . '.class.php';
    });

    the php documentation says that I should be able to put an anonymous function in here...
     
    lazerorca, Nov 18, 2014 IP
  6. sarahk

    sarahk iTamer Staff

    Messages:
    28,893
    Likes Received:
    4,553
    Best Answers:
    123
    Trophy Points:
    665
    #6
    I've never used them - not a fan of them in js either but that's me showing my age, I guess. From looking at the docs I can see there can be value in using them - but I'm not sure including all your class files quite what they had in mind.

    @PoPSiCLe will probably know.

    What error are you getting?
     
    sarahk, Nov 18, 2014 IP
  7. lazerorca

    lazerorca Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    1
    #7
    ok I found out what the issue is... something is up with the server software that I am using. when I do a phpinfo() it says I am running 5.6... but when I check the version in the terminal it says 5.3 which is not compatible with anonymous functions
     
    lazerorca, Nov 18, 2014 IP
    sarahk likes this.
  8. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #8
    ThePHPMaster, Nov 18, 2014 IP