You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When AbstractCollection contains objects which have both a method and property with the same name, the value can never be extracted from the method through ValueExtractorTrait::extractValue().
Steps to reproduce
class Person
{
publicfunction__construct(privatestring$name)
{
}
publicfunctionname(): string
{
return$this->name;
}
}
$collection = newRamsey\Collection\Collection();
$collection->add(newPerson('Bob'));
print_r($collection->columns('name'));
This seems to be because ValueExtractorTrait::extractValue() does not check if the property is actually accessible before trying to access it. It then proceeds to access it, causing the error, and then it never gets to checking whether a method exists with that same name which actually is accessible.
Possible solutions
One option would be to verify accessibility before attempting to access the property or method, but this would require use of reflection with obvious performance downsides.
Alternatively if it is detected that both the method and property exist of the same name, one could use a try/catch block to attempt to access them and then only throw an exception if both attempts failed.
Finally another "fix" could be to swap the position of accessing the property with that of accessing the method, which would work for the above use case (which is probably the most common). However, this would then cause a similar issue for objects with a private method and public property with the same name.
The text was updated successfully, but these errors were encountered:
Description
When
AbstractCollection
contains objects which have both a method and property with the same name, the value can never be extracted from the method throughValueExtractorTrait::extractValue()
.Steps to reproduce
The above triggers an error:
Expected behavior
Environment details
Cause
This seems to be because
ValueExtractorTrait::extractValue()
does not check if the property is actually accessible before trying to access it. It then proceeds to access it, causing the error, and then it never gets to checking whether a method exists with that same name which actually is accessible.Possible solutions
One option would be to verify accessibility before attempting to access the property or method, but this would require use of reflection with obvious performance downsides.
Alternatively if it is detected that both the method and property exist of the same name, one could use a try/catch block to attempt to access them and then only throw an exception if both attempts failed.
Finally another "fix" could be to swap the position of accessing the property with that of accessing the method, which would work for the above use case (which is probably the most common). However, this would then cause a similar issue for objects with a private method and public property with the same name.
The text was updated successfully, but these errors were encountered: