Other than the XP penalty, the only restrictions I'm aware of (beyond racial for some PrC's) is alignment. In other words, you can't be a Bard/Paladin, etc.
I've always approached the idea that a character is learning more about the "new" class as they are ganing XP before leveling up. Some players are better about playing this out than others.
In my first campaign, one player with a fighter character picked up a prayer book of Kord and a wooden holy symbol in town while he was still about 1500xp from leveling. He would mention that his character would read a little from the book every night when they camped, etc. He had the symbol of Kord painted onto his shield, too. When he leveled -big surprise- he took the level in cleric. This was also the guy who kept mentioning that he would practice footwork every evening so when he got to 4th, he took a point in DEX.
In the next campaign I ran (FRCS) my wife's character was a moon elf ranger from the Silver Marches. She wanted to be an arcane archer, so when they were in Silverymoon (at about 5th level) she "picked up" some books on magical theory from the college to study on the road. The idea being that she would take a level of wizard for her AA prereqs. She wouldn't take sorcerer because she thought it made no sense to suddenly "develop" this innate magical ability. (I knew I married her for a reason!

).
I have also had players just "decide" as they level that they now are also a 1st level Fighter, or Rogue, etc. But I try to discourage that. The way the above two players handled it worked great for me. It provided enough justification that the new class made sense.