Fix for late static binding

This commit is contained in:
Sebastian Meyer 2023-10-11 13:31:51 +02:00
parent b5ddbab61f
commit 2006073f94
3 changed files with 10 additions and 10 deletions

View File

@ -43,12 +43,12 @@ trait Getter
{ {
$method = '_get' . ucfirst($property); $method = '_get' . ucfirst($property);
if ( if (
property_exists(__CLASS__, $property) property_exists(get_called_class(), $property)
&& method_exists(__CLASS__, $method) && method_exists(get_called_class(), $method)
) { ) {
return $this->$method(); return $this->$method();
} else { } else {
throw new \InvalidArgumentException('Invalid property or missing getter method for property "' . __CLASS__ . '->' . $property . '".'); throw new \InvalidArgumentException('Invalid property or missing getter method for property "' . get_called_class() . '->' . $property . '".');
} }
} }

View File

@ -44,12 +44,12 @@ trait Setter
{ {
$method = '_set' . ucfirst($property); $method = '_set' . ucfirst($property);
if ( if (
property_exists(__CLASS__, $property) property_exists(get_called_class(), $property)
&& method_exists(__CLASS__, $method) && method_exists(get_called_class(), $method)
) { ) {
$this->$method($value); $this->$method($value);
} else { } else {
throw new \InvalidArgumentException('Invalid property or missing setter method for property "' . __CLASS__ . '->' . $property . '".'); throw new \InvalidArgumentException('Invalid property or missing setter method for property "' . get_called_class() . '->' . $property . '".');
} }
} }

View File

@ -40,11 +40,11 @@ trait Singleton
*/ */
final public static function getInstance(): self final public static function getInstance(): self
{ {
if (!isset(self::$singleton)) { if (!isset(static::$singleton)) {
$reflectionClass = new \ReflectionClass(__CLASS__); $reflectionClass = new \ReflectionClass(get_called_class());
self::$instance = $reflectionClass->newInstanceArgs(func_get_args()); static::$singleton = $reflectionClass->newInstanceArgs(func_get_args());
} }
return self::$singleton; return static::$singleton;
} }
/** /**