Advertisement
RahmanIEN

Operator Instanceof

Jun 23rd, 2023 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | Source Code | 0 0
  1. <?php
  2. // Definisi kelas
  3. class Person {
  4.     public $name;
  5. }
  6.  
  7. class Student extends Person {
  8.     public $studentId;
  9. }
  10.  
  11. // Pembuatan objek
  12. $person = new Person();
  13. $student = new Student();
  14.  
  15. // Penggunaan operator instanceof
  16. $result1 = $person instanceof Person;
  17. $result2 = $student instanceof Person;
  18. $result3 = $student instanceof Student;
  19.  
  20. echo $result1; // Output: 1 (true)
  21. echo $result2; // Output: 1 (true)
  22. echo $result3; // Output: 1 (true)
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement