diff --git a/language/operators.xml b/language/operators.xml index 207f9039a9..925d4971fe 100644 --- a/language/operators.xml +++ b/language/operators.xml @@ -1,5 +1,5 @@ - + Operators @@ -1192,11 +1192,12 @@ var_dump($a === $b); // bool(false) Using instanceof with classes - - ]]> - - &example.outputs; - +]]> + + &example.outputs; + + + instanceof can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class: Using instanceof with inherited classes - - ]]> - - &example.outputs; - +]]> + + &example.outputs; + + + To check if an object is not an instanceof a class, the logical not operator can be used. @@ -1255,6 +1262,7 @@ bool(true) class MyClass { } + $a = new MyClass; var_dump(!($a instanceof stdClass)); ?> @@ -1267,29 +1275,33 @@ bool(true) ]]> + + Lastly, instanceof can also be used to determine whether a variable is an instantiated object of a class that implements an interface: Using instanceof for class - - ]]> - - &example.outputs; - +]]> + + &example.outputs; + Using instanceof with other variables - - ]]> +]]> &example.outputs; @@ -1340,7 +1355,7 @@ bool(false) Avoiding classname lookups and fatal errors with instanceof in PHP 5.0 -