Better error handling of c::get and c::set?

I often have some options in my plugins and for getting these options I often use c::get but sometimes I write wrong, I write c::set instead. That’s completely my fault.

The problem is that I don’t get a warning or an error about it because these return exactly the same thing:

echo c::get('plugin.myplugin.value', 'a value');
echo c::set('plugin.myplugin.value', 'a value');

The result of both are:

a value

It makes it harder to know when I by accedent used c::set instead of c::get.

Possible solution

Does c::set need to return the default value? It could return null instead. I know this is a breaking adjustment and I guess many people will not agree with me on this one.

I wanted to make you aware of this “issue” anyway. :slight_smile:

Feedback appreciated. Thanks!

c::set return the $data class variable. If it would return null, you would not be able to set anything, or rather, c::get would always return null;

It sounds tricky/impossible to solve it that way then.

I think that sort of error handling has to take place in your brain, just make it accept that setters are there to set values and getters to get values :stuck_out_tongue_winking_eye: :innocent:

1 Like