Advertisement
Guest User

PHP Bug?

a guest
Oct 15th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.12 KB | None | 0 0
  1. <?php
  2.  
  3. class EstimateIt{
  4.     function rate(){
  5.         // ....
  6.         if($rate===false){
  7.             $this->log("Log Description",$data,array('response','request'));//no ampersand/live link to variable
  8.             $this->log_xml("response",$data->response);//LOGS **OMITTED**
  9.             $this->log_xml("request",$data->request);//LOGS **OMITTED**
  10.         }
  11.         // ....
  12.     }
  13.     function log($desc,$dataIn,$badkeys=array()){//no ampersand/live link to variable
  14.         $_str =$desc."\n\n";
  15.         $_str.=log_clean($dataIn,$badkeys);//no ampersand/live link to variable
  16.         file_put_contents(session_id().'__'.date('Ymd_His').'.txt', $_str);
  17.     }
  18.     function log_xml($filename,$xml_str){
  19.         file_put_contents($filename.'.xml',$xml_str);
  20.     }
  21. }
  22. function log_clean(&$obj, $exclude_keys, $omit_str='**OMMITTED**'){//DOES NOT WORK CORRECTLY
  23.     $_type=gettype($obj);
  24.     if($_type!='object' && $_type!='array'){return false;}
  25.     if(array_check($exclude_keys)){
  26.         foreach($obj as $k => $v){
  27.             if(@in_array($k,$exclude_keys,true)){
  28.                 if($_type=='object'){
  29.                     if(!basic_check($omit_str)){unset($obj->$k);}
  30.                     else{$obj->$k=$omit_str;}
  31.                 }else if($_type=='array'){
  32.                     if(!basic_check($omit_str)){unset($obj[$k]);}
  33.                     else{$obj[$k]=$omit_str;}
  34.                 }
  35.             }else{
  36.                 if(gettype($v)=='object' && ($v instanceof Traversable)){//
  37.                     log_clean($obj->$k,$exclude_keys,$omit_str);}
  38.                 else if(gettype($v)=='array'){
  39.                     log_clean($obj[$k],$exclude_keys,$omit_str);}
  40.             }
  41.         }
  42.     }
  43. }
  44. // =======  THE FIX! ======= \\
  45. function log_clean(&$obj, $exclude_keys, $omit_str='**OMMITTED**'){//WORKS CORRECTLY
  46.     $_type=gettype($obj);
  47.     if($_type!='object' && $_type!='array'){return false;}
  48.     if(array_check($exclude_keys)){
  49.         foreach($obj as $k => $v){
  50.             if(@in_array($k,$exclude_keys,true)){
  51.                 if($_type=='object'){
  52.                     if(!basic_check($omit_str)){unset($v);}
  53.                     else{$v=$omit_str;}
  54.                 }else if($_type=='array'){
  55.                     if(!basic_check($omit_str)){unset($v);}
  56.                     else{$v=$omit_str;}
  57.                 }
  58.             }else{
  59.                 if(gettype($v)=='object' && ($v instanceof Traversable)){//
  60.                     log_clean($v,$exclude_keys,$omit_str);}
  61.                 else if(gettype($v)=='array'){
  62.                     log_clean($v,$exclude_keys,$omit_str);}
  63.             }
  64.         }
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement