reyara8 Posted October 16, 2008 Share Posted October 16, 2008 1.Using the function declaration below, explain whether or not the function has any errors in it, what its purpose is and any optimizations you think can be made. Be sure to include descriptions of the passed arguments and function output, if any. Be sure to state your assumptions. 1 function get_employees_by_hierarchy( $_employee_id = 0,$_depth = 0,$_org_array = array() ) { 2 if ( $this->org_depth < $_depth ) { 3 $this->org_depth = $_depth; 4 } 5 $_depth++; 6 $_query = "SELECT * FROM employees WHERE "; 7 if ( !$_employee_id ) { 8 $_query .= "employee_manager_id IS NULL OR employee_manager_id = 0"; 9 } 10 else { 11 $_query .= "employee_manager_id = " . $this->dbh->quoteSmart( $_employee_id ); 12 } 13 $_result = $this->query( $_query ); 14 15 while ( $_row = $_result->fetchRow() ) { 16 $_row['depth'] = $_depth; 17 array_push( $_org_array, $_row ); 18 $_org_array = $this->get_employees_by_hierarchy( 19 $_row['employee_manager_id'], 20 $_depth, 21 $_org_array 22 ); 23 } 24 return $_org_array; 25 } Follow Up Questions: 2.Speculate why lines 2 – 4 are necessary. 3.Speculate why line 16 is necessary. Link to comment https://forums.phpfreaks.com/topic/128632-need-help-in-analysing-a-php-code/ Share on other sites More sharing options...
Barand Posted October 16, 2008 Share Posted October 16, 2008 You could at least have disguised that this is a homework assignment. Topic closed Link to comment https://forums.phpfreaks.com/topic/128632-need-help-in-analysing-a-php-code/#findComment-666652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.