Static class not instantiating (solved)

I have a static class with no constructor which I intend no one inheriting from and it having static values. However, the class fails to instantiate because the static instantiating method refuses to run. I have this

$all_users = //array of objects;
$username = "vain_glories";

    class pageOwner {
    static $instance = NULL;

    static function assignStatic() {
    var_dump($_GLOBALS['all_users']);
    if (is_null(self::$instance)) {
    foreach($all_users as $user=>$usernames) {
    if ($usernames == $username) {
    echo "ASSIGNED";
    self::$instance = $user;
    return;
    }
    else echo "NOT ASSIGNED";
    }
    }
    }
    }
    pageOwner::assignStatic();

I have moved that var_dump function both below that line, and also
tried dumping it without using globals but nothing dumps; it simply
outputs NULL and infringes every other output on the page. My error
log reports nothing as well. What could be wrong?

Update This example originates from a webshop where the format and exchange rate are decoupled from the text, which is stored in a cache file. With this solution, it is possible to use caching techniques and still have a dynamic exchange rate.

Where do you get the $all_users ? global variable won’t be automatically available without you put global $all_users;. But it would be better to pass it as parameter.

YES! YES! LOL! I just came online to edit that now. I also figured out I was calling the globals array wrongly. It should be $GLOBALS and not $_GLOBALS. How can I delete the question please??

1 Like

You can’t - it stays so the next time someone makes the same mistake they can easily find the answer.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.