Force PHP to error on non-declared variables? In objects?-Collection of common programming errors

Know this is an old post – but stumbled across it looking for a solution.

This is my final solution:

I have an abstract class that my classes extend that throws an error on magic __get and __set.

It’s nasty – but it works a treat!

It’s similar to suggestions above – but have also added ‘final’ to the method declaration to stop people overwriting it.

We also use a code sniffer to catch these – but I wanted to get my error messages ‘live’ as I coded, instead of having to wait for a report from the sniffer. (Also people can ignore sniff reports!)

Sample code below

Originally posted 2013-11-09 23:31:27.