{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4107","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4107/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4107/comments","events_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4107/events","html_url":"https://github.com/HaxeFoundation/haxe/issues/4107","id":65338677,"number":4107,"title":"Reflect.field issues","user":{"login":"ubald","id":754797,"avatar_url":"https://avatars.githubusercontent.com/u/754797?v=3","gravatar_id":"","url":"https://api.github.com/users/ubald","html_url":"https://github.com/ubald","followers_url":"https://api.github.com/users/ubald/followers","following_url":"https://api.github.com/users/ubald/following{/other_user}","gists_url":"https://api.github.com/users/ubald/gists{/gist_id}","starred_url":"https://api.github.com/users/ubald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubald/subscriptions","organizations_url":"https://api.github.com/users/ubald/orgs","repos_url":"https://api.github.com/users/ubald/repos","events_url":"https://api.github.com/users/ubald/events{/privacy}","received_events_url":"https://api.github.com/users/ubald/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-03-31T01:07:32Z","updated_at":"2015-04-01T03:19:02Z","closed_at":"2015-03-31T07:55:12Z","body":"The following code:\r\n\r\n```\r\npackage ;\r\nclass Main {\r\n    static public function main( ) {\r\n        trace(Reflect.field(A,'STATIC_FIELD'));\r\n        trace(Reflect.field(new A(),'STATIC_FIELD'));\r\n        trace(Reflect.field(B,'STATIC_FIELD'));\r\n        trace(Reflect.field(new B(),'STATIC_FIELD'));\r\n        trace(Reflect.field(C,'STATIC_FIELD'));\r\n        trace(Reflect.field(new C(),'STATIC_FIELD'));\r\n    }\r\n}\r\n\r\nclass A {\r\n    static public var STATIC_FIELD : String = \"A: hello world\";\r\n    public function new() {}\r\n}\r\n\r\nclass B extends A {\r\n    public function new() { super(); }\r\n}\r\n\r\nclass C extends B {\r\n    static public var STATIC_FIELD : String = \"C: hello world\";\r\n    public function new() { super(); }\r\n}\r\n```\r\n\r\nRunning with Haxe 3.1.3, mac cpp target, traces the following:\r\n\r\n```\r\nMain.hx:4: A: hello world\r\nMain.hx:5: A: hello world\r\nMain.hx:6: A: hello world\r\nMain.hx:7: A: hello world\r\nMain.hx:8: C: hello world\r\nMain.hx:9: C: hello world\r\n```\r\n\r\nWhile running with Haxe 3.2 rc2, mac cpp target, it traces the following:\r\n\r\n```\r\nMain.hx:4: A: hello world\r\nMain.hx:5: null\r\nMain.hx:6: null\r\nMain.hx:7: null\r\nMain.hx:8: C: hello world\r\nMain.hx:9: null\r\n```"},"comment":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/comments/88331682","html_url":"https://github.com/HaxeFoundation/haxe/issues/4107#issuecomment-88331682","issue_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4107","id":88331682,"user":{"login":"ubald","id":754797,"avatar_url":"https://avatars.githubusercontent.com/u/754797?v=3","gravatar_id":"","url":"https://api.github.com/users/ubald","html_url":"https://github.com/ubald","followers_url":"https://api.github.com/users/ubald/followers","following_url":"https://api.github.com/users/ubald/following{/other_user}","gists_url":"https://api.github.com/users/ubald/gists{/gist_id}","starred_url":"https://api.github.com/users/ubald/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ubald/subscriptions","organizations_url":"https://api.github.com/users/ubald/orgs","repos_url":"https://api.github.com/users/ubald/repos","events_url":"https://api.github.com/users/ubald/events{/privacy}","received_events_url":"https://api.github.com/users/ubald/received_events","type":"User","site_admin":false},"created_at":"2015-04-01T03:19:02Z","updated_at":"2015-04-01T03:19:02Z","body":"I ended up making a utility class to handle my needs\r\n\r\n```\r\npackage com.ubald.utils;\r\nclass ReflectionUtil {\r\n    static public function staticClassField( obj : Class<Dynamic>, field : String ) : Dynamic {\r\n        var type : Class<Dynamic> = obj;\r\n        var value : Dynamic = null;\r\n        while( type != null ) {\r\n            value = Reflect.field( type, field );\r\n            if ( value != null ) {\r\n                break;\r\n            }\r\n            type = Type.getSuperClass( type );\r\n        }\r\n        return value;\r\n    }\r\n    static public function staticInstanceField( obj : Dynamic, field : String ) : Dynamic {\r\n        return staticClassField( Type.getClass( obj ), field );\r\n    }\r\n}\r\n```\r\n\r\nIt works for me but while coding it I found out that ```Reflect.hasField( ChildClass, 'SOME_FIELD' );``` returns true if the static field is on a parent class, but ```Reflect.field( ChildClass, 'SOME_FIELD');``` returns null. They should at least have the same behavior."}}