Comment detail

メソッド名一覧の表示 (Nested Flatten)
get_class_methods関数を使うと簡単にメソッド一覧を取得できます。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
class Doukaku
{
    function Doukaku()
    {
    }

    function test_Doukaku()
    {
    }

    function hello()
    {
        print("hello world!");
    }

    function test_hello()
    {
    }
}

$doukaku = new Doukaku();
$result = array();
foreach (get_class_methods($doukaku) as $method) {
    if (strpos($method, "test_") === 0) {
        $result[] = $method;
    }
}

var_dump($result);
?>
実行するとこが抜けてたorz
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
class Doukaku
{
    function php()
    {
        print("php\n");
    }

    function test_php()
    {
        print("test_php\n");
    }

    function hello()
    {
        print("hello\n");
    }

    function test_hello()
    {
        print("test_hello\n");
    }
}

$doukaku = new Doukaku();
$result = array();
foreach (get_class_methods($doukaku) as $method) {
    if (strpos($method, "test_") === 0) {
        $doukaku->$method();
    }
}

?>
環境選びますがfnmatchとかいかがざんすか?
1
2
3
4
5
foreach (get_class_methods($doukaku) as $method) {
    if (fnmatch("test_*", $method)) {
        $doukaku->$method();
    }
}

Index

Feed

Other

Link

Pathtraq

loading...