girish.kc Posted November 2, 2010 Share Posted November 2, 2010 Hi, I am using a separate class for all the functions. And using using the following function "objectToArray" to convert the JSON decoded object to Array. Class file: class xyz { . . . . . function objectToArray($d) { if (is_object($d)) { $d = get_object_vars($d); } if (is_array($d)) { return array_map(__FUNCTION__, $d); } else { return $d; } } . . . } Main page: $obj = new xyz(); $arr = $obj->objectToArray($json_obj); Because the function "objectToArray" is recursive, array_map(__FUNCTION__, $d) is not able to applies the callback. And throws the warning "array_map() expects parameter 1 to be a valid callback". Need help! Girish Link to comment https://forums.phpfreaks.com/topic/217557-recursive-function-in-a-class/ Share on other sites More sharing options...
girish.kc Posted November 2, 2010 Author Share Posted November 2, 2010 I googled a bit and found a way to do it. return array_map(array($this, __FUNCTION__), $d); It worked...! Thanks, Girish Link to comment https://forums.phpfreaks.com/topic/217557-recursive-function-in-a-class/#findComment-1129442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.