Charles
Charles

Reputation: 11768

php ReflectionClass::getMethods does not returns the right number of methods

maybe it's a bug, i'm not sure.

Why when I execute this code:

<?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);
}

I get this result:

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"

Methods which are defined in interface appear two times. Is it a bug ?

Upvotes: 0

Views: 458

Answers (1)

BMBM
BMBM

Reputation: 16013

It seems to be a known bug that ReflectionClass::getMethods does not work reliably well on different PHP verions, see this user comment.

Upvotes: 1

Related Questions