My iPhone thinks it's always docked -- Volume slider disappeared with no audio output
I found a method that worked for me. If you're having a problem similar to mine and cleaning the dock did NOT work for you, try this at your own risk.
Disclaimer : This method might permanently damage your iPhone, mine is out of warranty so it wasn't a big deal if I damaged it, I would still need to pay for replacement.

I don't know what may have caused the phone to lock at the docked state, but my first thought is that there is a switch mechanism inside the dock connector. All I did was get a key and jam it there, and rotate it a bit until it got fixed.
Note: If I inserted the key there and did not rotate it, the problem is fixed temporarily until the key is removed. The only way I got rid of the problem completely is to rotate the key and push the pins downward.

If you try to insert the key and remove it, the problem still persists. I had to jam the key in deep and rotate it a few times (gently) to permanently fix this issue.  

Make sure you insert the key in the middle - left part of the dock connector, that's where  pin 11 is located (I think). 



After placing my phone on a dock again, I lost control over the sound. I did the same method with a bit more rotations using the key and now the problem is gone 100%. Not sure how, not sure why, but it worked.



If using a Key seems too risky for you, read below 

Use cotton wool from the end of a qtip (but not the qtip it's too wide to go in) use a nail file or a very thin screw driver to put the cotton wool inside the docking part and gently move back and forth. If you use alcohol even better. 

(PS i tried a lot of compressed air and a toothbrush and it didn't work - the iPhone was about 3 years old so it was filthy inside. The cotton wool came out surprisingly dirty - ie the tooth brush and the compressed air will work if it's a little dirty or there is a little bit of lint - but not if its very dirty.) 

Good luck.