Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Fixes E_NOTICE when using array_diff with PHP 5.4 fixes doctrine#50
Browse files Browse the repository at this point in the history
  • Loading branch information
shouze committed Jul 27, 2012
1 parent a5858db commit 0b838e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions lib/Doctrine/Lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,43 @@ public static function arrayDeepMerge()
return call_user_func_array(array('Doctrine_Lib', 'arrayDeepMerge'), $args);
break;
}
}

// Code from symfony sfToolkit class. See LICENSE
// code from cto at verylastroom dot com
/**
* arrayDiffSimple
*
* array arrayDiffSimple ( array array1 , array array2 )
*
* Like array_diff
*
* arrayDiffSimple() has exactly the same behavior than array_diff, but can handle
* only 2 arrays. PHP versions > 5.4.0 generate some NOTICE if you use array_diff
* sometimes because of array_diff internal behavior with (string) casts.
* This method solves the problem.
*
* @param array $array1
* @param array $array2
* @static
* @access public
* @return array
*/
public static function arrayDiffSimple($array1, $array2)
{
$diff = array();

foreach($array1 as $key => $val) {
if(!isset($array2[$key])) {
$diff[$key] = $val;
} else {
if(is_array($array2[$key]) && !is_array($val)) {
$diff[$key] = $val;
}
}
}

return $diff;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/Query/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ protected function _getDqlCallbackComponents($params = array())
$copy->free();

if ($componentsBefore !== $componentsAfter) {
return array_diff($componentsAfter, $componentsBefore);
return Doctrine_Lib::arrayDiffSimple($componentsAfter, $componentsBefore);
} else {
return $componentsAfter;
}
Expand Down Expand Up @@ -2168,4 +2168,4 @@ public function setDisableLimitSubquery($disableLimitSubquery)
{
$this->disableLimitSubquery = $disableLimitSubquery;
}
}
}

0 comments on commit 0b838e2

Please sign in to comment.