From 86f8ccb1d2b44d19d65f1d85c0ca7fcac9ed26ab Mon Sep 17 00:00:00 2001 From: Luke Watts Date: Sat, 15 Jun 2019 01:37:40 +0100 Subject: [PATCH] Adding ability to use classes as event handlers --- src/Magic.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Magic.php b/src/Magic.php index c836768..2adc947 100644 --- a/src/Magic.php +++ b/src/Magic.php @@ -165,13 +165,12 @@ public static function __strictCall(string $class, string $method, array $additi * __getMagicProperties * * Returns array of magic properties defined by annotation @property - - @author Luke Watts - * - * @since 1.0.0 + * @author Luke Watts + * + * @since 1.0.0 * * @param string $class - + * * @return array of [name => bit mask] */ public static function __getMagicProperties(string $class): array @@ -316,13 +315,15 @@ public static function __hasProperty(string $class, string $name) */ public function __call(string $name, array $args) { - $class = get_class($this); + $class = get_class($this); // calling event handlers if (self::__isEventProperty($class, $name)) { if (is_iterable($this->$name)) { foreach ($this->$name as $handler) { - $handler(...$args); + if ($handler !== null) { + $handler(...$args); + } } } elseif ($this->$name !== null) { throw new \Error("Property $class::$$name must be iterable or null, " . gettype($this->$name) . ' given.'); @@ -399,7 +400,7 @@ public function &__get(string $name) */ public function __set(string $name, $value) { - $class = get_class($this); + $class = get_class($this); if (self::__hasProperty($class, $name)) { $this->$name = $value;