Previously a class which I'm now rebuilding had a member variable $settings
which was an array of settings, strangely enough.
class MyClass {
public $settings = array();
public function __construct() {
if( empty( $this->settings ) ) {
$this->settings = require( 'settings.php' ); // e.g. return array('setting1'=>4);
}
}
}
These settings were accessed by $object->settings['keyname'];
The means by which these keys are accessed has been moved into a method now. However, the application itself is riddled with calls to $object->settings['keyname']
. I was wondering is there a way which I can catch any calls to the $settings
member variable and return it using the new function.
I've looked at __get($name)
but $name
only contains settings
rather than the array key which I need. What I'd need to pass would be the keyname to the my $object->get()
method.
The reason I want to do this is so that I can trigger errors in a log file showing me where the deprecated calls to $object->settings[]
are without breaking the application. Obviously setting $setting to private would give me lots of fatal errors and I could work through but there are multiple developers working on this codebase which I'd prefer not to break. If I could implement this as a temporary solution it'd help.
I realise there are repositories etc which we could use so that I could work on it separately and check it in afterwards but I'm looking for a quick, temporary solution as we're porting our codebase to Git soonish.