ccampbell / chromephp

class for logging PHP variables to Google Chrome console
http://www.chromelogger.com
1.38k stars 450 forks source link

json_encode returns empty string if logged object property is a Resource or has some "weird" chars. #61

Open szaqal83 opened 7 years ago

szaqal83 commented 7 years ago

I'm trying to log a object representing a AD user (using Adldap2 library) and x-chromelogger-data header contains empty string. After some digging I've found (I think) that these properties are causing problems for json_encode:

object(Adldap\Connections\Ldap)#5 (4) { ["connection":protected]=> resource(1) of type (ldap link) ["bound":protected]=> bool(true) ["useSSL":protected]=> bool(false) ["useTLS":protected]=> bool(true) }

["objectguid"]=> array(1) { [0]=> string(16) "4�ǘ=�F�Q9 ���" }

["objectsid"]=> array(1) { [0]=> string(28) "9aSg^�p�f3 " }

whole object looks like this:

object(Adldap\Models\User)#9 (9) { ["exists"]=> bool(true) ["dateFormat"]=> string(11) "Y-m-d H:i:s" ["dn":protected]=> string(58) "CN=Lena Oronowicz,OU=Tarnobrzeg,OU=Pracownicy,DC=PUW,DC=RZ" ["query":protected]=> object(Adldap\Query\Builder)#11 (15) { ["columns"]=> array(0) { } ["filters"]=> array(3) { ["and"]=> array(3) { [0]=> array(3) { ["field"]=> string(11) "objectclass" ["operator"]=> string(1) "=" ["value"]=> string(18) "\70\65\72\73\6f\6e" } [1]=> array(3) { ["field"]=> string(14) "objectcategory" ["operator"]=> string(1) "=" ["value"]=> string(18) "\70\65\72\73\6f\6e" } [2]=> array(3) { ["field"]=> string(3) "anr" ["operator"]=> string(1) "=" ["value"]=> string(30) "\6c\6f\72\6f\6e\6f\77\69\63\7a" } } ["or"]=> array(0) { } ["raw"]=> array(0) { } } ["limit"]=> int(1) ["paginated"]=> bool(false) ["sortByField":protected]=> string(0) "" ["sortByDirection":protected]=> string(0) "" ["sortByFlags":protected]=> NULL ["dn":protected]=> string(12) "dc=PUW,dc=RZ" ["recursive":protected]=> bool(true) ["read":protected]=> bool(false) ["raw":protected]=> bool(false) ["nested":protected]=> bool(false) ["connection":protected]=> object(Adldap\Connections\Ldap)#5 (4) { ["connection":protected]=> resource(2) of type (ldap link) ["bound":protected]=> bool(true) ["useSSL":protected]=> bool(false) ["useTLS":protected]=> bool(true) } ["grammar":protected]=> object(Adldap\Query\Grammar)#10 (0) { } ["schema":protected]=> object(Adldap\Schemas\ActiveDirectory)#6 (0) { } } ["schema":protected]=> object(Adldap\Schemas\ActiveDirectory)#6 (0) { } ["attributes":protected]=> array(79) { ["objectclass"]=> array(4) { [0]=> string(3) "top" [1]=> string(6) "person" [2]=> string(20) "organizationalPerson" [3]=> string(4) "user" } [0]=> string(11) "objectclass" ["cn"]=> array(1) { [0]=> string(14) "Lena Oronowicz" } [1]=> string(2) "cn" ["sn"]=> array(1) { [0]=> string(9) "Oronowicz" } [2]=> string(2) "sn" ["description"]=> array(1) { [0]=> string(6) "u10812" } [3]=> string(11) "description" ["givenname"]=> array(1) { [0]=> string(4) "Lena" } [4]=> string(9) "givenname" ["distinguishedname"]=> array(1) { [0]=> string(58) "CN=Lena Oronowicz,OU=Tarnobrzeg,OU=Pracownicy,DC=PUW,DC=RZ" } [5]=> string(17) "distinguishedname" ["instancetype"]=> array(1) { [0]=> string(1) "4" } [6]=> string(12) "instancetype" ["whencreated"]=> array(1) { [0]=> string(17) "20131031070153.0Z" } [7]=> string(11) "whencreated" ["whenchanged"]=> array(1) { [0]=> string(17) "20170403210032.0Z" } [8]=> string(11) "whenchanged" ["displayname"]=> array(1) { [0]=> string(14) "Lena Oronowicz" } [9]=> string(11) "displayname" ["usncreated"]=> array(1) { [0]=> string(6) "857040" } [10]=> string(10) "usncreated" ["memberof"]=> array(4) { [0]=> string(31) "CN=I-XIII,OU=Grupy,DC=PUW,DC=RZ" [1]=> string(34) "CN=Wydzial_I,OU=Grupy,DC=PUW,DC=RZ" [2]=> string(42) "CN=Gr_Otrs_Customers,OU=Grupy,DC=PUW,DC=RZ" [3]=> string(38) "CN=Gr_Tarnobrzeg,OU=Grupy,DC=PUW,DC=RZ" } [11]=> string(8) "memberof" ["usnchanged"]=> array(1) { [0]=> string(8) "18293551" } [12]=> string(10) "usnchanged" ["name"]=> array(1) { [0]=> string(14) "Lena Oronowicz" } [13]=> string(4) "name" ["objectguid"]=> array(1) { [0]=> string(16) "4�ǘ=�F�Q9 ���" } [14]=> string(10) "objectguid" ["useraccountcontrol"]=> array(1) { [0]=> string(3) "512" } [15]=> string(18) "useraccountcontrol" ["badpwdcount"]=> array(1) { [0]=> string(1) "0" } [16]=> string(11) "badpwdcount" ["codepage"]=> array(1) { [0]=> string(1) "0" } [17]=> string(8) "codepage" ["countrycode"]=> array(1) { [0]=> string(1) "0" } [18]=> string(11) "countrycode" ["homedirectory"]=> array(1) { [0]=> string(24) "\\deimos\home\loronowicz" } [19]=> string(13) "homedirectory" ["homedrive"]=> array(1) { [0]=> string(2) "Z:" } [20]=> string(9) "homedrive" ["badpasswordtime"]=> array(1) { [0]=> string(18) "131338854817418281" } [21]=> string(15) "badpasswordtime" ["lastlogoff"]=> array(1) { [0]=> string(1) "0" } [22]=> string(10) "lastlogoff" ["lastlogon"]=> array(1) { [0]=> string(18) "131357615859570312" } [23]=> string(9) "lastlogon" ["pwdlastset"]=> array(1) { [0]=> string(18) "131357268328437500" } [24]=> string(10) "pwdlastset" ["primarygroupid"]=> array(1) { [0]=> string(3) "513" } [25]=> string(14) "primarygroupid" ["objectsid"]=> array(1) { [0]=> string(28) "9aSg^�p�f3 " } [26]=> string(9) "objectsid" ["accountexpires"]=> array(1) { [0]=> string(1) "0" } [27]=> string(14) "accountexpires" ["logoncount"]=> array(1) { [0]=> string(3) "727" } [28]=> string(10) "logoncount" ["samaccountname"]=> array(1) { [0]=> string(10) "loronowicz" } [29]=> string(14) "samaccountname" ["samaccounttype"]=> array(1) { [0]=> string(9) "805306368" } [30]=> string(14) "samaccounttype" ["userprincipalname"]=> array(1) { [0]=> string(17) "loronowicz@PUW.RZ" } [31]=> string(17) "userprincipalname" ["lockouttime"]=> array(1) { [0]=> string(1) "0" } [32]=> string(11) "lockouttime" ["objectcategory"]=> array(1) { [0]=> string(49) "CN=Person,CN=Schema,CN=Configuration,DC=PUW,DC=RZ" } [33]=> string(14) "objectcategory" ["dscorepropagationdata"]=> array(5) { [0]=> string(17) "20161014195806.0Z" [1]=> string(17) "20161014194900.0Z" [2]=> string(17) "20150414103534.0Z" [3]=> string(17) "20150414103450.0Z" [4]=> string(17) "16010714223649.0Z" } [34]=> string(21) "dscorepropagationdata" ["lastlogontimestamp"]=> array(1) { [0]=> string(18) "131356773375214757" } [35]=> string(18) "lastlogontimestamp" ["msds-supportedencryptiontypes"]=> array(1) { [0]=> string(1) "0" } [36]=> string(29) "msds-supportedencryptiontypes" ["mail"]=> array(1) { [0]=> string(28) "loronowicz@rzeszow.uw.gov.pl" } [37]=> string(4) "mail" ["axiisenabled"]=> array(1) { [0]=> string(4) "TRUE" } [38]=> string(12) "axiisenabled" ["dn"]=> string(58) "CN=Lena Oronowicz,OU=Tarnobrzeg,OU=Pracownicy,DC=PUW,DC=RZ" } ["original":protected]=> array(79) { ["objectclass"]=> array(4) { [0]=> string(3) "top" [1]=> string(6) "person" [2]=> string(20) "organizationalPerson" [3]=> string(4) "user" } [0]=> string(11) "objectclass" ["cn"]=> array(1) { [0]=> string(14) "Lena Oronowicz" } [1]=> string(2) "cn" ["sn"]=> array(1) { [0]=> string(9) "Oronowicz" } [2]=> string(2) "sn" ["description"]=> array(1) { [0]=> string(6) "u10812" } [3]=> string(11) "description" ["givenname"]=> array(1) { [0]=> string(4) "Lena" } [4]=> string(9) "givenname" ["distinguishedname"]=> array(1) { [0]=> string(58) "CN=Lena Oronowicz,OU=Tarnobrzeg,OU=Pracownicy,DC=PUW,DC=RZ" } [5]=> string(17) "distinguishedname" ["instancetype"]=> array(1) { [0]=> string(1) "4" } [6]=> string(12) "instancetype" ["whencreated"]=> array(1) { [0]=> string(17) "20131031070153.0Z" } [7]=> string(11) "whencreated" ["whenchanged"]=> array(1) { [0]=> string(17) "20170403210032.0Z" } [8]=> string(11) "whenchanged" ["displayname"]=> array(1) { [0]=> string(14) "Lena Oronowicz" } [9]=> string(11) "displayname" ["usncreated"]=> array(1) { [0]=> string(6) "857040" } [10]=> string(10) "usncreated" ["memberof"]=> array(4) { [0]=> string(31) "CN=I-XIII,OU=Grupy,DC=PUW,DC=RZ" [1]=> string(34) "CN=Wydzial_I,OU=Grupy,DC=PUW,DC=RZ" [2]=> string(42) "CN=Gr_Otrs_Customers,OU=Grupy,DC=PUW,DC=RZ" [3]=> string(38) "CN=Gr_Tarnobrzeg,OU=Grupy,DC=PUW,DC=RZ" } [11]=> string(8) "memberof" ["usnchanged"]=> array(1) { [0]=> string(8) "18293551" } [12]=> string(10) "usnchanged" ["name"]=> array(1) { [0]=> string(14) "Lena Oronowicz" } [13]=> string(4) "name" ["objectguid"]=> array(1) { [0]=> string(16) "4�ǘ=�F�Q9 ���" } [14]=> string(10) "objectguid" ["useraccountcontrol"]=> array(1) { [0]=> string(3) "512" } [15]=> string(18) "useraccountcontrol" ["badpwdcount"]=> array(1) { [0]=> string(1) "0" } [16]=> string(11) "badpwdcount" ["codepage"]=> array(1) { [0]=> string(1) "0" } [17]=> string(8) "codepage" ["countrycode"]=> array(1) { [0]=> string(1) "0" } [18]=> string(11) "countrycode" ["homedirectory"]=> array(1) { [0]=> string(24) "\\deimos\home\loronowicz" } [19]=> string(13) "homedirectory" ["homedrive"]=> array(1) { [0]=> string(2) "Z:" } [20]=> string(9) "homedrive" ["badpasswordtime"]=> array(1) { [0]=> string(18) "131338854817418281" } [21]=> string(15) "badpasswordtime" ["lastlogoff"]=> array(1) { [0]=> string(1) "0" } [22]=> string(10) "lastlogoff" ["lastlogon"]=> array(1) { [0]=> string(18) "131357615859570312" } [23]=> string(9) "lastlogon" ["pwdlastset"]=> array(1) { [0]=> string(18) "131357268328437500" } [24]=> string(10) "pwdlastset" ["primarygroupid"]=> array(1) { [0]=> string(3) "513" } [25]=> string(14) "primarygroupid" ["objectsid"]=> array(1) { [0]=> string(28) "9aSg^�p�f3 " } [26]=> string(9) "objectsid" ["accountexpires"]=> array(1) { [0]=> string(1) "0" } [27]=> string(14) "accountexpires" ["logoncount"]=> array(1) { [0]=> string(3) "727" } [28]=> string(10) "logoncount" ["samaccountname"]=> array(1) { [0]=> string(10) "loronowicz" } [29]=> string(14) "samaccountname" ["samaccounttype"]=> array(1) { [0]=> string(9) "805306368" } [30]=> string(14) "samaccounttype" ["userprincipalname"]=> array(1) { [0]=> string(17) "loronowicz@PUW.RZ" } [31]=> string(17) "userprincipalname" ["lockouttime"]=> array(1) { [0]=> string(1) "0" } [32]=> string(11) "lockouttime" ["objectcategory"]=> array(1) { [0]=> string(49) "CN=Person,CN=Schema,CN=Configuration,DC=PUW,DC=RZ" } [33]=> string(14) "objectcategory" ["dscorepropagationdata"]=> array(5) { [0]=> string(17) "20161014195806.0Z" [1]=> string(17) "20161014194900.0Z" [2]=> string(17) "20150414103534.0Z" [3]=> string(17) "20150414103450.0Z" [4]=> string(17) "16010714223649.0Z" } [34]=> string(21) "dscorepropagationdata" ["lastlogontimestamp"]=> array(1) { [0]=> string(18) "131356773375214757" } [35]=> string(18) "lastlogontimestamp" ["msds-supportedencryptiontypes"]=> array(1) { [0]=> string(1) "0" } [36]=> string(29) "msds-supportedencryptiontypes" ["mail"]=> array(1) { [0]=> string(28) "loronowicz@rzeszow.uw.gov.pl" } [37]=> string(4) "mail" ["axiisenabled"]=> array(1) { [0]=> string(4) "TRUE" } [38]=> string(12) "axiisenabled" ["dn"]=> string(58) "CN=Lena Oronowicz,OU=Tarnobrzeg,OU=Pracownicy,DC=PUW,DC=RZ" } ["modifications":protected]=> array(0) { } ["timestampFormat":protected]=> string(9) "YmdHis.0Z" }

checking encoding of 'objectguid' and 'objectsid' using mb_detect_encoding() returns UTF-8 so it looks ok I think. I've added some extra code inside _convert function of ChromePHP to bypass those props and Object showed inside Firefox console.

Encoding object through:

base64_encode(utf8_encode(json_encode($object)))

results non empty string so I think that there is something wrong with the _convert function.