From: it at oh-barcelona dot com
Operating system: Windows
PHP version: 4.3.2
PHP Bug Type: Variables related
Bug description: SORT_ASC when passed into a function can NOT be passed as a string

Description:
------------
Hello,
I've found a perplexing bug with sorting flags. When you create a
function to create (for example) an dynamic array_multisort() and one of
the arguements which is passed is a SORT_ASC (or any other flag) which is
used to create the array_multisort() it MUST be passed without quotes and
not as a string.

In the example below you will see that if you gettype() of the $arg the
SORT_DESC returns an integer not a string when passed without quotes and a
string with.

If the SORT flag is passed as a string the array_multisort acts as if it
were null.

This stops me from setting the SORT flag via if statement.

I have written a work around but this problem should be addressed because
if you settype() a string it becomes "0".

The function call is:
$ new_array = array_column_sort($someArray,'column',SORT_DESC)

The function does not work if you use:
$sortFlag = "SORT_ASC";
$ new_array = array_column_sort($someArray,'column',$sortFlag )



Reproduce code:
---------------
function array_column_sort(){
$args = func_get_args();
$array = array_shift($args);
// make a temporary copy of array for which will fix the
// keys to be strings, so that array_multisort() doesn't
// destroy them
$array_mod = array();
foreach ($array as $key => $value)
$array_mod['_' . $key] = $value;

$i = 0;
$multi_sort_line = "return array_multisort( ";
foreach ($args as $arg) {
$i++;
if ( is_string($arg) ){
foreach ($array_mod as $row_key => $row){
$sort_array[$i][] = $row[$arg];
}
}else{
$sort_array[$i] = $arg;
}
$multi_sort_line .= "\$sort_array[" . $i . "], ";
}
$multi_sort_line .= "\$array_mod );";
eval($multi_sort_line);
// now copy $array_mod back into $array, stripping off the "_"
// that we added earlier.
$array = array();
foreach ($array_mod as $key => $value)
$array[ substr($key, 1) ] = $value;

return $array;
}

Expected result:
----------------
The array should be sorted by column and SORT flag.

Actual result:
--------------
The array_multisort only excepts the SORT flag without quotes and not as a
string.

--
Edit bug report at [url]http://bugs.php.net/?id=25879&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=25879&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=25879&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=25879&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=25879&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=25879&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=25879&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=25879&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=25879&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=25879&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=25879&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=25879&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=25879&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=25879&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=25879&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=25879&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=25879&r=float[/url]