mirror of
https://github.com/opencultureconsulting/php-basics.git
synced 2025-04-13 00:00:47 +02:00
Fix for late static binding
This commit is contained in:
parent
b5ddbab61f
commit
2006073f94
@ -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 . '".');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 . '".');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user