berlindb / core

All of the required core code
MIT License
253 stars 27 forks source link

Magic functions starting with "get_" are not working as intended #46

Open JJJ opened 4 years ago

JJJ commented 4 years ago

Originally, part of what I'd wanted Berlin to be able to do, was allow for object variables to be retrieved from methods inside the calling class, like this very bad example below:

Say you want $this->thing but you always want it formatted a certain way. In theory, you could just add this method and it would always get returned formatted as you wanted it:

public function get_thing() {
    return sanitize_key( $this->thing );
}

Unfortunately, the magic getter isn't actually working because all of the class definitions currently require - as a best practice - that their default object variables be defined. This causes PHP to always skip the magic getter and use the property that is defined.

The bug here, is that you should be able to override properties simply but you can't, even though there is code inside of Base::__get() that tries to support it.

You also cannot work around it by omitting object properties, because they are required as part of the way that Berlin expects for classes to be written.