Where you need to detect a small object accurately, from a distance, but space is the problem , then the O7 series IP65 rated photoelectric sensor from ifm electronic is worth a second look. The overall dimensions are just 15mm x 20mm x 9mm. The sensor is available as a diffuse reflection unit with background suppression, as a retro-reflective sensor with polarisation filter or as through-beam transmitters or receivers.
The background-suppressed diffuse variants are offered with three different fixed ranges of 30mm, 50mm, and 100mm. Retroreflective units work up to 1m, and 1.5m is achieved with the separate transmitter/receiver through-beam. In each case a light/dark switching function is provided by the unit selection. The light spot diameter of just 2.5mm in some units means it is almost laser like in terms of performance, but without the cost or safety concerns of a laser.
Connection to the sensor is made using a standard M8 connector on a short 200mm cable. A range of accessories is available, ensuring quick installation and easy alignment.