There is no such law, and cop/inspector/security guard whatever, he was full of BS. He may have believed it -- training in such issues has been notoriously poor at all levels of government (including, I sometimes think, Capitol Hill). Next time refer such twits to this recent tidbit.

When someone hassles you, ask their badge #, their agency, and specific citation of the law they claim you are violating.