أَخْبَرَنَا أَبُو طَاهِرٍ الْفَقِيهُ، أنبأ أَبُو بَكْرٍ الْقَطَّانُ، ثنا هَاشِمُ بْنُ الْجُنَيْدِ أَبُو صَالِحٍ الْبَذَشِيُّ الْقُومِسِيُّ، ثنا زَيْدُ بْنُ الْحُبَابِ، حَدَّثَنِي مُحَمَّدُ بْنُ مُسْلِمٍ الطَّائِفِيُّ، ثنا عَمْرُو بْنُ دِينَارٍ، عَنِ ابْنِ عَبَّاسٍ، قَالَ: " مَنْ كَانَتْ عِنْدَهُ شَهَادَةٌ فَلَا يَقُلْ: لَا أَشْهَدُ بِهَا إِلَّا عِنْدَ إِمَامٍ، وَلَكِنَّهُ يَشْهَدُ، لَعَلَّهُ يَرْجِعُ وَيَرْعَوِي ". هَذَا مَوْقُوفٌ، وَهُوَ الصَّحِيحُ، وَقَدْ رُوِيَ مَرْفُوعًا وَلَا يَصِحُّ رَفْعُهُ.
Amr bin Dinar narrates from Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) that whoever holds a testimony should not say: I will testify to it only before an imam (ruler); rather, he should testify, so that perhaps he will turn back or desist.
This is mawquf (a Companion's statement), and that is what is correct; it has also been narrated as marfu' (from the Prophet), but its attribution to the Prophet is not authentic.