Welcome to my series on every PHP keyword and its usage. Today’s item:
instanceof operator allows you to check if an object is an instance of a particular class (or a class that extends a particular class) or implements a particular interface.
Most of the time you’ll directly check if an object implements a specific class, but you can also check it against a class name stored inside a variable.
- You cannot use
instanceofwith a string literal, including the special
- You cannot check if an object uses a specific trait using
Author Callum Muir