@@ -30,7 +30,7 @@ abstract class Struct implements Arrayable, JsonSerializable, Castable
3030 */
3131 public function __construct (array $ properties = [])
3232 {
33- $ reflections = $ this -> getReflectionProperties ();
33+ $ reflections = static :: getReflectionProperties ();
3434
3535 foreach ($ reflections as $ reflection ) {
3636 $ name = $ reflection ->getName ();
@@ -89,20 +89,38 @@ protected function buildInstance($class, $value)
8989 return new $ class ($ value );
9090 }
9191
92+ /**
93+ * Get the property names.
94+ *
95+ * @return array
96+ */
97+ public static function getPropertyNames ()
98+ {
99+ $ reflections = static ::getReflectionProperties ();
100+
101+ $ result = [];
102+
103+ foreach ($ reflections as $ reflection ) {
104+ $ name = $ reflection ->getName ();
105+ $ result [] = $ name ;
106+ }
107+
108+ return $ result ;
109+ }
110+
92111 /**
93112 * Get the properties.
94113 *
95114 * @return array
96115 */
97116 public function getProperties ()
98117 {
99- $ reflections = $ this -> getReflectionProperties ();
118+ $ reflections = static :: getReflectionProperties ();
100119
101120 $ result = [];
102121
103122 foreach ($ reflections as $ reflection ) {
104123 $ name = $ reflection ->getName ();
105-
106124 $ result [$ name ] = $ this ->{$ name };
107125 }
108126
@@ -126,7 +144,7 @@ public function toArray()
126144 *
127145 * @return \ReflectionProperty[]
128146 */
129- protected function getReflectionProperties ()
147+ protected static function getReflectionProperties ()
130148 {
131149 if (isset (static ::$ cache [static ::class])) {
132150 return static ::$ cache [static ::class];
0 commit comments