Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created August 20, 2013 04:55
Show Gist options
  • Save shoyan/6277243 to your computer and use it in GitHub Desktop.
Save shoyan/6277243 to your computer and use it in GitHub Desktop.
メソッドの呼び出し回数を数えるサンプル
<?php
class CallCount
{
public $call_counts = array();
function counts($method) {
if(!isset($this->call_counts[$method])) {
$this->call_counts[$method] = 0;
}
$this->call_counts[$method]++;
}
}
class World
{
function __construct()
{
$this->callCount = new CallCount();
}
function hello()
{
echo 'hello';
$this->callCount->counts(__FUNCTION__);
}
}
$world = new World();
$world->hello();
$world->hello();
$world->hello();
var_dump($world->callCount->call_counts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment