Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

is_a() versus instanceof

<?php

class A {}

var_dump(new a instanceof A);
// true

var_dump(new a instanceof A::class);
// Fatal error

var_dump(is_a(new a, A::class));
// true

var_dump(is_a(new a, A);
// Undefined constant A

is_a() et instanceof représentent la même fonctionnalité : vérifier si un objet est d’une classe spécifique. Pourtant, ils fonctionnent de manière différente.

L’utilisation de l’opérateur ::class est sûre dans les deux cas.

L’utilisation d’un nom est un nom de classe pour instanceof, alors que c’est un nom de constante avec is_a(). Cela peut prêter à confusion.

See Also

PHP Features

Last updated: 11 October 2026