Tried this successfully at the start of this year. As others have said, with Canadian pr and departure and arrival on SAME day (not just <24 hours), you MAY be given a same day transit visa stamp without needing to apply for a specific visa before hand. But there are two caveats
1. This is purely at officers discretion. So you cannot plan for it, an officer might just refuse you and there is no way to dispute that.
2. This is meant for transit and cannot be used to say visit London attractions during a long layover.
So if you MUST exit airport, better get a visa beforehand. But if you are going to be in airport already and want to try your luck, ask an officer politely if you may exit airport for a transit hotel. And hope that officer is convinced.