How to properly use an OPB917BOCZ photoswitch?
It's OK to connect Anode to V+ OR Cathode to 0V but if both are connected, it will not limit IR Diode current and burn out inside.  ( Test with DMM in diode test mode for 1V or so with + on Anode)

The proper way to test is to use a series R in either Anode or cathode connection to V+ and 0V (respectively) and  operate at 10mA and no more than 20mA using Ohm's Law such as (5V-Vf=3.8V) so 3.8V/380 ohm = 10mA.    The LED has a wide (+40%) voltage tolerance of 1.3V typ to 1.8V max @ 20mA and reduces with current. So using 10mA target current is optimal target.

Also it may get wounded or damaged if reverse polarity >2V is applied.

Visible LEDs are similar except have a forward voltage drop that is greater 2V typ for R or Y and 3V typ for B or W.

http://www.mouser.com/ds/2/414/OPB917BZ-962256.pdf   datasheet