array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'function.class-exists.php', 1 => 'class_exists', ), 'up' => array ( 0 => 'ref.classobj.php', 1 => 'Sınıf ve Nesne İşlevleri', ), 'prev' => array ( 0 => 'function.class-alias.php', 1 => 'class_alias', ), 'next' => array ( 0 => 'function.enum-exists.php', 1 => 'enum_exists', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'tr', 'path' => 'reference/classobj/functions/class-exists.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
class_exists — Sınıf tanımlı mı diye bakar
Bu işlev belirtilen sınıfın tanımlı olup olmadığına bakar.
sınıf
Sınıf ismi. İsim eşleştirilirken harf büyüklüğü dikkate alınmaz.
otomatik_yükle
Yüklü değilse autoload çağrısı yapılıp yapılmayacağı.
Örnek 1 - class_exists() örneği
<?php
// Kullanmayı denemeden önce böyle bir sınıf var mı diye bak
if (class_exists('MyClass')) {
$myclass = new MyClass();
}
?>
Örnek 2 - autoload
bağımsız değişken örneği
<?php
spl_autoload_register(function ($class_name) {
include $class_name . '.php';
// Check to see whether the include declared the class
if (!class_exists($class_name, false)) {
throw new LogicException("Unable to load class: $class_name");
}
});
+if (class_exists(MyClass::class)) {
$myclass = new MyClass();
}
?>