Skip to content

Instantly share code, notes, and snippets.

@itthinx
Created March 11, 2015 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itthinx/da9eb5128236121d31bf to your computer and use it in GitHub Desktop.
Save itthinx/da9eb5128236121d31bf to your computer and use it in GitHub Desktop.
PHP Bug Warning: uksort(): Array was modified by the user comparison function
<?php
/**
* The following will produce this result:
*
* Warning: uksort(): Array was modified by the user comparison function in /Users/kento/Sites/uksort.php on line 12
* set = array ( 'apple' => 'green', 'color' => 'yellow', 'wine' => 'white', 'yoghurt' => 'frozen', )
*
* See also https://bugs.php.net/bug.php?id=50688
**/
ini_set( 'display_errors', 1 );
$set = array( 'color' => 'yellow', 'apple' => 'green', 'yoghurt' => 'frozen', 'wine' => 'white' );
function foo( $a, $b ) {
new Exception();
return strcmp( $a, $b );
}
uksort( $set, 'foo' );
echo ' set = ' . var_export( $set,true );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment