Support » Plugins » Hacks » Class function calling another class as global (wrong scope?)

  • Resolved e


    Hi guys,

    I am trying to call a class function from another class function but when calling global $hcdb; it loads as NULL. I read some time ago about having to declare it as a global but think it was only for variables. Any ideas? Sounds like quite a basic thing…

    Stripped code of the files below:

    main.php (the one that loads first)



    class HcDatabase {
      function checknicename() { return 1; }
    $hcdb = new HcDatabase;


    class HcFunctions {
      function format() {
        global $hcdb;
        var_dump($hcdb); // returns NULL
    $hc = new HcFunctions;

Viewing 1 replies (of 1 total)
  • e


    The code belonged to a former developer, and wasn’t intended for WP. Just rewritten everything again to have a logical OOP structure that creates particular objects inside methods when needed, etc. Also adapted it to use functions so they are accessible through WP without hacks and everything keeps simplified, logical, scalable and secure

Viewing 1 replies (of 1 total)
  • The topic ‘Class function calling another class as global (wrong scope?)’ is closed to new replies.