php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14315 array_unique stopped working on arrays after 4.0.4pl1
Submitted: 2001-12-02 15:48 UTC Modified: 2001-12-02 16:05 UTC
From: truth at ichaos dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.5 OS: RedHat 6.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
36 + 2 = ?
Subscribe to this entry?

 
 [2001-12-02 15:48 UTC] truth at ichaos dot com
I upgraded from php-4.0.4pl1 to php-4.0.5 and 4.0.6 and in both instances, the script I run array_unique in only returns one item in my array. Here is a script that will work as expected in php-4.0.4pl1 but not in any version higher:

$array1[] = array(0 => "one");
$array1[] = array(0 => "two");
$array1[] = array(0 => "two");
$array1[] = array(0 => "three");
$array1[] = array(0 => "three");
$array1[] = array(0 => "three");

echo "<PRE>";
echo "Before unique: <BR>";
var_dump($array1);

$array1 = array_values(array_unique($array1));

echo "After unique: <BR>";
var_dump($array1);
echo "</PRE>";

===
Output for 4.0.4pl1 looks like:
Before unique: 
array(6) {
  [0]=>
array(1) {
    [0]=>
string(3) "one"
  }
  [1]=>
array(1) {
    [0]=>
string(3) "two"
  }
  [2]=>
array(1) {
    [0]=>
string(3) "two"
  }
  [3]=>
array(1) {
    [0]=>
string(5) "three"
  }
  [4]=>
array(1) {
    [0]=>
string(5) "three"
  }
  [5]=>
array(1) {
    [0]=>
string(5) "three"
  }
}
After unique: 
array(3) {
  [0]=>
array(1) {
    [0]=>
string(3) "one"
  }
  [1]=>
array(1) {
    [0]=>
string(3) "two"
  }
  [2]=>
array(1) {
    [0]=>
string(5) "three"
  }
}

===
Output for versions later look like:
Before unique: 
array(6) {
  [0]=>
array(1) {
    [0]=>
string(3) "one"
  }
  [1]=>
array(1) {
    [0]=>
string(3) "two"
  }
  [2]=>
array(1) {
    [0]=>
string(3) "two"
  }
  [3]=>
array(1) {
    [0]=>
string(5) "three"
  }
  [4]=>
array(1) {
    [0]=>
string(5) "three"
  }
  [5]=>
array(1) {
    [0]=>
string(5) "three"
  }
}
After unique: 
array(1) {
  [0]=>
array(1) {
    [0]=>
string(3) "one"
  }
}

===
configure lines for both:
 php-4.0.4pl1:
 './configure' '--with-apache=../apache_1.3.14' '--prefix=/usr' '--enable-safe-mode' '--with-exec-dir=/usr/bin' '--with-zlib' '--with-config-file-path=/etc/php3/apache' '--disable-debug' '--enable-magic-quotes' '--enable-debugger' '--enable-bcmath' '--enable-track-vars' '--enable-trans-sid' '--enable-wddx' '--with-imap' '--with-ldap' '--with-ibm-db2' '--with-system-regex' '--with-informix' '--with-pdflib=/usr/local/pdflib' '--enable-inline-optimization' '--without-gd'

 php-4.0.6
 './configure' '--with-apache=../apache_1.3.14' '--prefix=/usr' '--enable-safe-mode' '--with-exec-dir=/usr/bin' '--with-zlib' '--with-config-file-path=/etc/php3/apache' '--disable-debug' '--enable-magic-quotes' '--enable-debugger' '--enable-bcmath' '--enable-track-vars' '--enable-trans-sid' '--enable-wddx' '--with-mcrypt' '--with-imap' '--with-ldap' '--with-ibm-db2' '--with-system-regex' '--with-informix' '--with-pdflib=/usr/local/pdflib' '--enable-inline-optimization' '--without-gd'

===
As a side note, in order to get php-4.0.6 to compile for both IBM DB2 and Informix, I had to apply the following:
diff -Naur php-4.0.6.orig/main/internal_functions.c php-4.0.6/main/internal_func
tions.c
--- php-4.0.6.orig/main/internal_functions.c    Fri Nov 30 11:40:20 2001
+++ php-4.0.6/main/internal_functions.c Fri Nov 30 11:40:39 2001
@@ -32,11 +32,11 @@
 #include "ext/zlib/php_zlib.h"
 #include "ext/bcmath/php_bcmath.h"
 #include "ext/imap/php_imap.h"
-#include "ext/informix/php_informix.h"
 #include "ext/ldap/php_ldap.h"
 #include "ext/mcrypt/php_mcrypt.h"
 #include "ext/mysql/php_mysql.h"
 #include "ext/odbc/php_odbc.h"
+#include "ext/informix/php_informix.h"
 #include "ext/pcre/php_pcre.h"
 #include "ext/pdf/php_pdf.h"
 #include "ext/posix/php_posix.h"

But thats a whole other bug report. Mcrypt would also fail to compile in 4.0.4pl1, prolly I need to downgrade it.

Those are the only differences I can think of between these versions.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-02 15:58 UTC] derick@php.net
Not a bug  in 4.0.5 or later, but in 4.0.4(pl1). The manual states:

Note:  Two  elements  are  considered equal if and only if (string)
     $elem1   ===   (string)   $elem2.   In   words:   when  the  string
     representation is the same.

The string representation of 'array(0 => something);' is always 'Array':

<?php
    echo array(0 => "one");
?>

outputs:
Array

The manual also states:

   Warning

   This was broken in PHP 4.0.4!

So this is not a bug.

Derick
 [2001-12-02 16:05 UTC] truth at ichaos dot com
So because it worked as I expected it to, that was a bug?

So how do I make sure that my array of arrays is unique, is there an easy way?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 09:01:27 2024 UTC