Don’t use IsValid in your Doctrine Models – a warning
September 9, 2010 in Doctrine, PHP, Web Development
Recently for a project i’ve been making heavy use of Doctrine. In one of the models I had a method to check to see if the object was valid under a certain set of conditions. I named this function isValid .. and it had 2 params. Little did I know that this was actually overriding an existing deep rooted isValid which gets fired on saving the object to the DB. Bummer.
So this is a quick warning to all you Doctrine users. Unless you want to actually override the isValid method for saving, call your check method function something else!
Is this Doctrine 1 or 2? I wouldn’t expect this to be a problem in Doctrine 2 since your entity classes don’t extend any Doctrine classes and Doctrine generated proxy classes don’t have an isValid() method.
It’s Doctrine 1.
Hopefully Doctrine 2 will be better.. I have lots of little personal qualms about it.. but not to say it’s not good.. just that it could be better.