PHP Manual

拡張インターフェイス

拡張インターフェイスの関数群を使用すると、 名前つきのカウンタを好きなだけ作成してそれぞれ別の設定にすることができます。 基本インターフェイスと拡張インターフェイスを両方同時に使うことも可能です。

例1 "counter" の拡張インターフェイス

<?php
function print_counter_info($counter)
{
    if (
is_resource($counter)) {
        
printf("Counter's name is '%s' and is%s persistent. Its current value is %d.\n",
            
counter_get_meta($counterCOUNTER_META_NAME),
            
counter_get_meta($counterCOUNTER_META_IS_PERSISTENT) ? '' ' not',
            
counter_get_value($counter));
    } else {
      print 
"Not a valid counter!\n";
    }
}

if ((
$counter_one counter_get_named("one")) === NULL) {
    
$counter_one counter_create("one"0COUNTER_FLAG_PERSIST);
}
counter_bump_value($counter_one2);
$counter_two counter_create("two"5);
$counter_three counter_get_named("three");
$counter_four counter_create("four"2COUNTER_FLAG_PERSIST COUNTER_FLAG_SAVE COUNTER_FLAG_NO_OVERWRITE);
counter_bump_value($counter_four1);

print_counter_info($counter_one);
print_counter_info($counter_two);
print_counter_info($counter_three);
print_counter_info($counter_four);
?>

これをはじめて実行したときの結果は次のようになります。

Counter's name is 'one' and is persistent. Its current value is 2.
Counter's name is 'two' and is not persistent. Its current value is 5.
Not a valid counter!
Counter's name is 'four' and is persistent. Its current value is 3.

同じ PHP インスタンスでもう一度実行すると、結果はこのようになります。

Counter's name is 'one' and is persistent. Its current value is 4.
Counter's name is 'two' and is not persistent. Its current value is 5.
Not a valid counter!
Counter's name is 'four' and is persistent. Its current value is 4.

さらにもう一度、今度は 別の PHP インスタンスで 実行したときの結果は次のとおりです。

Counter's name is 'one' and is persistent. Its current value is 2.
Counter's name is 'two' and is not persistent. Its current value is 5.
Not a valid counter!
Counter's name is 'four' and is persistent. Its current value is 5.

PHP Manual
[お役立ちリンク集]

NPO法人の設立(東京・大阪) 東京や大阪などNPO法人を設立する場合の注意点等を紹介

不動産・賃貸・マンション 不動産・賃貸・マンションに関する用語集です。

堺市の入院・内科

大阪の賃貸探し 大阪で賃貸を探している方は大阪ホームへ

東京の賃貸マンション 東京で賃貸を探すなら東京賃貸.orgへ