Answers for "php instanceof"

PHP
3

php instanceof

<?php
/*
 * 
 * opcode number: 138
 */
$obj = new A();

if ($obj instanceof A) {
   echo 'A';
}
?>
Posted by: Guest on June-14-2020
1

how work instanceof php method

class MyClass {
}

$o1 = new MyClass();
$o2 = new MyClass();
$name = 'MyClass';

// in the cases below, $a gets boolean value true
$a = $o1 instanceof MyClass;
$a = $o1 instanceof $name;
$a = $o1 instanceof $o2;

// counter examples:
$b = 'b';
$a = $o1 instanceof 'MyClass'; // parse error: constant not allowed
$a = false instanceof MyClass; // fatal error: constant not allowed
$a = $b instanceof MyClass;    // false ($b is not an object)
Posted by: Guest on August-18-2020
1

php instanceof

<?php
class MyClass {}
class AnotherClass extends MyClass{}
$obj = new AnotherClass();

if($obj instanceof AnotherClass) {
  echo "The object is AnotherClass";
}
// The object is also an instance of the class it is derived from
if($obj instanceof MyClass) {
  echo "The object is MyClass<br>";
}
?>
Posted by: Guest on March-20-2021
0

php instanceof

$myObject instanceof MyClass

//usualy in if()
if($myObject instanceof MyClass)
{
  //Do it
}
Posted by: Guest on October-08-2021

Browse Popular Code Answers by Language