ID:               42270
 Updated by:       [EMAIL PROTECTED]
 Reported By:      steven dot mccoy at miru dot hk
-Status:           Open
+Status:           Feedback
 Bug Type:         JSON related
 Operating System: Ubuntu 7.04
 PHP Version:      5.2.4RC1-dev
 New Comment:

So this has nothing to do with JSON? Please reclassify if that is true
and fix the summary to contain what the bug is really about..


Previous Comments:
------------------------------------------------------------------------

[2007-08-16 12:11:34] steven dot mccoy at miru dot hk

The situation I'm using it in is where the browser sends an array of
objects to PHP.  The PHP scripts uses PEAR::DB_DataObject to generate an
array of objects inside a database table, I then use
array_diff/array_udiff to calculate what is new, what has changed, and
what should be deleted.  The array_diff for items that have not changed
fails in 5.2 because PHP fails be able to compare some of the stdClass
objects.

 $new_products = array_filter($products,
array('Order','is_new_product'));
 debug('new_order_products: '.count($new_products).' found');
 $old_products = array_diff($new_products, $products);
 debug('old_order_products: '.count($old_products).' calculated');
 $updated_products = array_udiff($old_products, $current_products,
array('Order', 'product_compare'));
 debug('updated_order_products: '.count($updated_products).' found');
 $deleted_products = array_udiff($current_products, $products,
array('Order', 'product_compare_by_id'));
 debug('deleted_order_products: '.count($deleted_products).' found');


PEAR::DB_DataObject returns table rows as objects, the PHP JSON module
defaults to objects, but can include arrays of objects as shown
previously.

As a workaround I rebuilt PHP 5.1.6 from Ubuntu 6.10 on 7.04.  If
someone can provide a array_udiff function that can compare objects like
before that would be great :-)

If the current circumstances are not clear, I will repeat:  PHP 5.1.6
generates the expected result output as shown, PHP 5.2 does not.

------------------------------------------------------------------------

[2007-08-16 11:52:54] [EMAIL PROTECTED]

Here's what I get for the encode:

{"first":[{"second":2},"two","three"]}

So actually you have another object inside the first, here's
var_dump($obj);

object(stdClass)#1 (1) {
  ["first"]=>
  array(3) {
    [0]=>
    object(stdClass)#2 (1) {
      ["second"]=>
      int(2)
    }
    [1]=>
    string(3) "two"
    [2]=>
    string(5) "three"
  }
}

And using json_decode($json, true):

array(1) {
  ["first"]=>
  array(3) {
    [0]=>
    array(1) {
      ["second"]=>
      int(2)
    }
    [1]=>
    string(3) "two"
    [2]=>
    string(5) "three"
  }
}

So what's the bug?

------------------------------------------------------------------------

[2007-08-16 11:46:15] [EMAIL PROTECTED]

See also bug #42303

------------------------------------------------------------------------

[2007-08-13 21:34:06] crrodriguez at suse dot de

Workaround : use array_udiff with a supplied callback function or use
only arrays.

------------------------------------------------------------------------

[2007-08-12 06:54:01] steven dot mccoy at miru dot hk

Reproduced with the Win32 CVS build:

PHP 5.2.4RC1-dev (cli) (built: Aug 12 2007 00:04:25)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/42270

-- 
Edit this bug report at http://bugs.php.net/?id=42270&edit=1

Reply via email to