2011-09-15 27 views
0

也许这是一个错误,我不知道。php ReflectionClass :: getMethods不返回正确数量的方法

为什么当我执行这个代码:

<?php 

class testReflection implements Serializable { 
    public function serialize() { 
    } 
    public function unserialize($data) { 
    } 
    public function getData() { 
    } 
} 

class testReflection2 implements arrayaccess { 
    public function offsetSet($offset, $value) { 
    } 
    public function offsetExists($offset) { 
    } 
    public function offsetUnset($offset) { 
    } 
    public function offsetGet($offset) { 
    } 
    public function getData() { 
    } 
} 

$c = new ReflectionClass('testReflection'); 

foreach ($c->getMethods() as $method) { 
    var_dump($method->name); 
} 
echo '========================'; 
$c = new ReflectionClass('testReflection2'); 

foreach ($c->getMethods() as $method) { 
    var_dump($method->name); 
} 

我得到这样的结果:这是在接口中定义

string(9) "serialize" 
string(11) "unserialize" 
string(7) "getData" 
string(11) "unserialize" 
string(9) "serialize" 
======================== 
string(9) "offsetSet" 
string(12) "offsetExists" 
string(11) "offsetUnset" 
string(9) "offsetGet" 
string(7) "getData" 
string(11) "offsetUnset" 
string(9) "offsetSet" 
string(9) "offsetGet" 
string(12) "offsetExists" 

方法出现两次。这是一个错误吗?

回答

1

这似乎是一个已知的错误,ReflectionClass :: getMethods在不同的PHP版本上无法正常工作,请参阅此user comment