2929use DateTime ;
3030use Exception ;
3131use JsonSerializable ;
32+ use ReflectionMethod ;
3233use ReturnTypeWillChange ;
3334
3435/**
@@ -461,7 +462,7 @@ public function __set(string $key, $value = null)
461462 // so maybe wants to do sth with null value automatically
462463 $ method = 'set ' . str_replace (' ' , '' , ucwords (str_replace (['- ' , '_ ' ], ' ' , $ key )));
463464
464- if (method_exists ($ this , $ method ) && $ method !== 'setAttributes ' ) {
465+ if (method_exists ($ this , $ method ) && $ method !== 'setAttributes ' && $ this -> isPublic ( $ method ) ) {
465466 $ this ->{$ method }($ value );
466467
467468 return $ this ;
@@ -476,6 +477,13 @@ public function __set(string $key, $value = null)
476477 return $ this ;
477478 }
478479
480+ private function isPublic (string $ method ): bool
481+ {
482+ $ reflection = new ReflectionMethod ($ this , $ method );
483+
484+ return $ reflection ->isPublic ();
485+ }
486+
479487 /**
480488 * Magic method to allow retrieval of protected and private class properties
481489 * either by their name, or through a `getCamelCasedProperty()` method.
@@ -501,7 +509,7 @@ public function __get(string $key)
501509
502510 // if a get* method exists for this key,
503511 // use that method to insert this value.
504- if (method_exists ($ this , $ method )) {
512+ if (method_exists ($ this , $ method ) && $ this -> isPublic ( $ method ) ) {
505513 $ result = $ this ->{$ method }();
506514 }
507515
0 commit comments