Start · Sprachen · PHP · Referenz · is_a

is_a

Funktion

Prüft, ob ein Objekt eine Instanz einer Klasse ist (oder eines Kindes davon). Meist besser: <code>instanceof</code>.

seit PHP 4.2.0 Kategorie: oop

Signatur

is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool

Beschreibung

Für Strings mit $allow_string = true. Praktisch, wenn man nur den Klassennamen als String hat.

Parameter

Name Typ Default Beschreibung
$object_or_class Pflicht mixed Objekt/Klasse.
$class Pflicht string Zu prüfende Klasse.
$allow_string bool false Strings erlauben.

Rückgabewert

Typ
bool

Beispiele

Basis

<?php

is_a($obj, \Exception::class);  // wie $obj instanceof \Exception