Unlike many issues with dates, this one is purely a result of a wrong API design. It does not make sense to "set a component" of a date all by itself (unlike hours/minutes/seconds in a day), so an API that allows you to so is plain broken.
Correct API would be to set the components D,M,Y all at once and have them validated on the spot before returning a valid Date value.
Comments
Unlike many issues with dates, this one is purely a result of a wrong API design. It does not make sense to "set a component" of a date all by itself (unlike hours/minutes/seconds in a day), so an API that allows you to so is plain broken.
Correct API would be to set the components D,M,Y all at once and have them validated on the spot before returning a valid Date value.