sebastianbergmann / comparator

Provides the functionality to compare PHP values for equality.
BSD 3-Clause "New" or "Revised" License
6.99k stars 68 forks source link

added failing test for derived class #83

Open exeba opened 4 years ago

exeba commented 4 years ago

When a derived class redeclares a private member of the base class, the "Exporter" class fails to recognize that.

exeba commented 4 years ago

https://github.com/sebastianbergmann/exporter/pull/35 will make tests pass

sebastianbergmann commented 4 years ago

Even with https://github.com/sebastianbergmann/exporter/pull/35, I do not understand what it is you are trying to report.

exeba commented 4 years ago
class Base 
{
    private $privateField;

    public function __construct($value)
    {
        $this->privateField = $value;
    }

}

class Derived extends Base 
{
    private $privateField;

    public function __construct($value, $parentValue)
    {
        parent::__consturct($parentValue);
        $this->privateField = $value;
    }
}

$object1 = new Derived(10, 200);
$object2 = new Derived(100, 200);

The two objects should be considered different, but since Derived declares a private field that already exists in Base, the field by field comparison considers only the $privateField in the Base class, ingoring the one in Derived.