SQLSTATE[HY000]: General error: could not call class constructor
This rather vague error message has been popping up in some of my integration tests lately. It’s a PHP error in PDO querying MySQL that happens when you’re using the setFetchMode method of the PDOStatement. If you use the fetchMode of “FETCH_CLASS” you can get this error in one of three ways:
- The class you specified has not been included/required so when PDO gets results, it cannot create an object of the class you specified since it doesn’t have that class definition.
- Properties on the class you specified have been marked as protected or private and there aren’t any setters for them so PDO can’t set the properties on the new object.
- You used the optional third argument “ctorargs” to give constructor arguments on your new object however your arguments are incorrect and don’t match those on the class.
Hope this helps other poor souls out there trying to figure this error out.