get_called_class() in PHP 5.3

| | コメント(27) | トラックバック(0)

__CLASS__ 定数の遅延静的束縛版といったところでしょうか。

<?php

class A
{
    public static function whose()
    {
        return get_called_class();
    }
}

class B extends A
{
    public static function whose()
    {
        return parent::whose();
    }
}

class C extends A
{
    public static function whose()
    {
        return A::whose();
    }
}

echo 'A: ', A::whose(), PHP_EOL;
echo 'B: ', B::whose(), PHP_EOL;
echo 'C: ', C::whose(), PHP_EOL;
A: A
B: B
C: A

ActiveRecord のようにクラスメソッドがバカスカ生えるクラスに使えるかもですね。でもここでは継承される事を想定したシングルトンの例を上げます。そんなのありか!

<?php

class Hoge
{
    private static $instances = array();
    
    protected function __construct()
    {
        if (array_key_exists(get_called_class(), self::$instances))
        {
            throw new RuntimeException('もう作っちゃらめ!');
        }
    }
    
    final public static function getInstance()
    {
        $callee = get_called_class();
        if (!array_key_exists($callee, self::$instances))
        {
            self::$instances[$callee] = new static();
        }
        
        return self::$instances[$callee];
    }
    
    public function __clone()
    {
        throw new RuntimeException('クローン作っちゃらめ!');
    }
    
    public function __toString()
    {
        return get_class($this) . '(' . spl_object_hash($this) . ')';
    }
}

class Fuga extends Hoge
{
}

class Piyo extends Fuga
{
}

echo Hoge::getInstance(), PHP_EOL;
echo Fuga::getInstance(), PHP_EOL;
echo Piyo::getInstance(), PHP_EOL;
echo Hoge::getInstance(), PHP_EOL;
echo Fuga::getInstance(), PHP_EOL;
echo Piyo::getInstance(), PHP_EOL;
Hoge(ea3b5927dbfffe7c0456ff51c413a384)
Fuga(0e67c95a7d082c779dc82db7e8554d9c)
Piyo(3b3af9abb7c1ee816230684be1ec11dc)
Hoge(ea3b5927dbfffe7c0456ff51c413a384)
Fuga(0e67c95a7d082c779dc82db7e8554d9c)
Piyo(3b3af9abb7c1ee816230684be1ec11dc)

トラックバック(0)

このブログ記事を参照しているブログ一覧: get_called_class() in PHP 5.3

このブログ記事に対するトラックバックURL: http://zenith.sakura.ne.jp/mt/mt-tb.cgi/36

コメント(27)

Very first factor , A large thank you for you to open my eyes.

This can be a great website write-up and I defer to you what you've said below. I've previously subscribed for a RSS feed in Firefox and are going to be your regular reader. Many thanks for the time in writing the submit.

Many thanks for your good publish. I'll take the notes you've written.

Hiya, I am really glad I’ve found this information. Today bloggers publish only about gossips and internet and this is actually annoying. A good site with exciting content, this is what I need. Thanks for keeping this website, I will be visiting it. Do you do newsletters? Cant find it.

A brilliant article. I liked it a lot. Do you know of any similar places?

Very good brief and gang me a lot. Thank you I looking for your facts.

Pisón Lan Egipto   aturdido e manolo blahnik zapatos I1U7M dejó su familia no e nojado debería colapsar  Tsui Oriole es manolo blahnik madrid te espectro Young Jin sinuoso cavidad heces subida  plantado leer perdone,manolo blahnik zapatos I1U7M dejó su familia no e! ?

Dominancia en circulación el cuerpo de la hoja de Brahma fugaz, los binoculares ya ha estallado r manolo blahnik zapatos o

immediatamente sciolto fuori, guard貌 verso il fondo, not for 猫 il principale, poi cuando ricord貌 che lui not for 猫 una identity within questa scuola, take place potrebbe

XRumerTest :

Hello. And Bye.

XRumerTest :

Hello. And Bye.

DorothyTut :

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0":
captcha regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? There are a lot of demo videos about XEvil in YouTube.
Good luck!


XRumer20170718

ArleneDub :

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0":
captcha recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another subtypes of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? There are a lot of demo videos about XEvil in YouTube.
See you later!


XRumer20170721

ArleneDub :

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil":
captcha recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another size-types of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? There are a lot of introducing videos about XEvil in YouTube.
Good luck!


XRumer20170721

ArleneDub :

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil":
captcha recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? You can find a lot of demo videos about XEvil in YouTube.
See you later ;)


XRumer20170721

Flossiewed :

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0":
captcha regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another types of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? You can find a lot of impessive videos about XEvil in YouTube.
Good luck ;)


XRumer20170725

Flossiewed :

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil 3.0":
captcha breaking of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? There are a lot of impessive videos about XEvil in YouTube.
Good luck!


XRumer20170725

Carolynfooli :

Absolutely NEW update of SEO/SMM software "XRumer 16.0 + XEvil":
captchas solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? There are a lot of impessive videos about XEvil in YouTube.
You read it - then IT WORKS!
See you later!


XRumer201708

Carolynfooli :

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil":
captcha breaking of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another subtypes of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? You can find a lot of impessive videos about XEvil in YouTube.
You read it - then IT WORKS!
See you later ;)


XRumer201708

Carolynfooli :

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0":
captcha solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? There are a lot of demo videos about XEvil in YouTube.
You read it - then IT WORKS!
See you later ;)


XRumer201708

Carolynfooli :

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil":
captcha solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another size-types of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? You can find a lot of demo videos about XEvil in YouTube.
You read it - then IT WORKS!
Good luck!


XRumer201708

Carolynfooli :

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil":
captcha solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? There are a lot of demo videos about XEvil in YouTube.
You read it - then IT WORKS!
See you later!


XRumer201708

Carolynfooli :

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil 3.0":
captcha solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another types of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? You can find a lot of demo videos about XEvil in YouTube.
You read it - then IT WORKS!
See you later ;)


XRumer201708

Carolynfooli :

Absolutely NEW update of SEO/SMM software "XRumer 16.0 + XEvil 3.0":
captcha regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another subtypes of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? You can find a lot of introducing videos about XEvil in YouTube.
You read it - then IT WORKS!
See you later!


XRumer201708

Carolynfooli :

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil":
captchas regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another types of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? You can find a lot of impessive videos about XEvil in YouTube.
You read it - then IT WORKS!
Good luck ;)


XRumer201708

Carolynfooli :

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil 3.0":
captcha solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another types of captchas,
with highest precision (80..100%) and highest speed (100 img per second).
You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms.

Interested? There are a lot of introducing videos about XEvil in YouTube.
You read it - then IT WORKS!
Good luck ;)


XRumer201708

Leeannoweva :

SEO / SMMソフトウェア "XRumer 16.0 + XEvil 3.0"の革新的なアップデート:
Google、Facebook、Bing、Hotmail、SolveMedia、Yandex、
さらに8400種類以上のキャプチャ、
最高精度(80..100%)と最高速度(毎秒100イグジット)を備えています。
XEvil 3.0は、XRumer、GSA SER、ZennoPoster、Srapebox、Senukeなど100以上の他のプログラマに最も人気のあるSEO / SMMプログラムに接続できます。

興味がある? YouTubeでXEvilに関するビデオを紹介しています。
あなたはそれを読んで - 次にそれは働く!
がんばろう ;)


XRumer201708c

コメントする


画像の中に見える文字を入力してください。

このブログ記事について

このページは、zenithが2008年8月14日 20:27に書いたブログ記事です。

ひとつ前のブログ記事は「HTTP ストリーム ignore_errors オプション in PHP 5.3」です。

次のブログ記事は「遅延静的束縛と forward_static_call()」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。

Powered by Movable Type 4.12