If you have an old iPhone lying around whose contract is over, or because you bought a newer version, you can continue using it as a iPod touch. Apple has put up a support article which lists out instructions to convert your iPhone to be used as an iPod Touch with Wi-Fi support only.
If you upgrade your iPhone to a newer model or cancel your wireless service account/tariff for your iPhone, it is possible to continue using your older iPhone without an active cellular service (using it with Wi-Fi only).
For older versions of iPhone (1G/2G), you will need to have the original SIM card, without which it would be useless. However, iPhone 3G and 3GS can use any SIM to activate the phone to be used as a iPod Touch.
So don’t throw away or sell that old iPhone yet, you can create a nice little gift for someone who has been longing to get a iPod Touch.