I'm trying to understand how PHP manages memory and variables with static methods in extended classes. I've got three classes one entitled Model, User1, User2. Hence:
class Model {
static public $structure;
static public $name;
static function get_structure() {
return self::$structure = file_get_contents(self::$name.'.json');
}
}
class User1 extends Model {
}
class User2 extends Model {
}
User1::$name = 'User1';
User2::$name = 'User2';
echo User1::get_structure();
echo User2::get_structure();
If I run User1::get_structure(); for some reason it doesn't populate the result accordingly, it seems to be grabbing the value of User2 (the last $name value declared).
I'm operating on the assumption that declaring User2 and extending Model creates a completely separate scope for my $name property. So User1 and User2 are declared as separate classes with the same structure as Model. Then I can statically define values for them in separate scopes.
I'm now however questioning that. If I extend and call the same $name variable do they both point back to the Model class? Or does it only create a separate scope when I declare each class with new User1(); and new User2();?
Thanks.