Tek Nesne Arayüz Sınıfı

index.php

PHP
17 lines
<?php
header('Content-Type: text/html; charset=utf-8');
require("Autoload.php");
class test implements Singleton_Interface{
public static function getInstance(){
return new static;
}
}
class test2{
public static function getInstance(){
return new static;
}
}
$b=new test;
if ($b instanceof Singleton_Interface) {
echo get_class(test::getInstance());
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Autoload.php

PHP
22 lines
<?php
if(!function_exists('__autoload')){
function __autoload($sinifAdi){
if(class_exists('Zend',false)){
if(is_int(strrpos($sinifAdi,'_Interface'))){
Zend::loadClass($sinifAdi);
}else{
Zend::loadInterface($sinifAdi);
}
}else{
if(!defined('__CLASS_PATH__')){
define('__CLASS_PATH__',realpath(dirname(__FILE__)));
}
$dosya=__CLASS_PATH__ . '/'.str_replace('_','/',$sinifAdi).'.php';
if(!file_exists($dosya)){
throw new Exception('Sınıf Dosyası Yüklenemiyor '.$sinifAdi);
}else{
require_once $dosya;
}
}
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Singleton/Interface.php

PHP
6 lines
<?php
if (!interface_exists('Singleton_Interface')) {
interface Singleton_Interface{
public static function getInstance();
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Çıktısı

Markdown
1 lines
test
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Sizin Değerli Görüşlerinize İhtiyacımız Var.