[ENTITY] Fix entity->has to access private properties with closure bindTo

This commit is contained in:
Diogo Peralta Cordeiro 2021-05-02 00:14:24 +01:00 committed by Hugo Sales
parent da3754efba
commit b6d7d46719
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -35,7 +35,10 @@ abstract class Entity
{
if (Formatting::startsWith($name, 'has')) {
$prop = Formatting::camelCaseToSnakeCase(Formatting::removePrefix($name, 'has'));
return isset($this->{$prop});
// https://wiki.php.net/rfc/closure_apply#proposal
$private_property_accessor = function($prop) { return isset($this->{$prop}); };
$private_property_accessor = $private_property_accessor->bindTo($this, get_called_class());
return $private_property_accessor($prop);
}
throw new \Exception("Entity::{$name} called with bogus arguments: " . print_r($arguments, true));
}