Don't let "...string old_mbox, string new_mbox);" fool you. You have to add the server and port to the mailbox name also. So it would be something like:
imap_renamemailbox($mailbox, "{localhost:143}$oldfolder", "{localhost:143}$newfolder")
Just thought I would point it out, it took me a while to figure it out.