From:             danielc at analysisandsolutions dot com
Operating system: Windows 2000 and OS X 10.3
PHP version:      5CVS-2004-02-03 (dev)
PHP Bug Type:     Reproducible crash
Bug description:  casting arrays to objects and back

Description:
------------
Found PEAR DB's getAssoc() method didn't work correctly when in
DB_FETCHMODE_OBJECT mode.  See pear/DB/tests/18get.phpt for that.

I pared it down a bit and then Adam Trachtenberg whittled it down even
farther.  Here's what he found:

   1) Use an array with a string key: array('a' => 1)
   2) Cast it to an object and call get_object_vars()
      on the result.
   3) Assign this cast object to an array with
      multiple elements.
   4) Call print_r() on the resulting array.

   If I remove any of these, the crash goes away.


Reproduce code:
---------------
<?php
$array = array(1);
$element = (object) array('a' => 1);
get_object_vars($element);
$array[] = $element;
print_r($array);
?>

Expected result:
----------------
Array
(
    [0] => 1
    [1] => stdClass Object
        (
            [a] => 1
        )

)


Actual result:
--------------
~~~~~ WINDOWS 2000 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Array
(
    [0] => 1
    [1] => stdClass Object
        (
            [a] => 1130656883
        )

)

~~~~~ OS X 10.3, PHP = beta 3 ~~~~~~~~~
No Output.

~~~~~ OS X 10.3, PHP = recent CVS ~~~~~
Array
(
    [0] => 1
    [2] => stdClass Object
        (
            [a] =>

... backtrace ...

#0  0x00271308 in _zend_is_inconsistent (ht=0x5a5a5a5a, file=0x3183f8
"/usr/local/cvs/php/php-src/Zend/zend_hash.c", line=504) at
/usr/local/cvs/php/php-src/Zend/zend_hash.c:53
#1  0x00273384 in zend_hash_destroy (ht=0x5a5a5a5a) at
/usr/local/cvs/php/php-src/Zend/zend_hash.c:504
#2  0x002658a8 in _zval_dtor (zvalue=0xbfffe710, __zend_filename=0x3178bc
"/usr/local/cvs/php/php-src/Zend/zend_operators.c", __zend_lineno=510) at
/usr/local/cvs/php/php-src/Zend/zend_variables.c:52
#3  0x0025d240 in _convert_to_string (op=0xbfffe710,
__zend_filename=0x317b5c "/usr/local/cvs/php/php-src/Zend/zend.c",
__zend_lineno=256) at
/usr/local/cvs/php/php-src/Zend/zend_operators.c:510
#4  0x0026691c in zend_make_printable_zval (expr=0xace8d0,
expr_copy=0xbfffe710, use_copy=0xbfffe720) at
/usr/local/cvs/php/php-src/Zend/zend.c:256
#5  0x002669dc in zend_print_zval_ex (write_func=0x208fa0
<php_body_write_wrapper>, expr=0xace8d0, indent=0) at
/usr/local/cvs/php/php-src/Zend/zend.c:275
#6  0x00266984 in zend_print_zval (expr=0xace8d0, indent=0) at
/usr/local/cvs/php/php-src/Zend/zend.c:266
#7  0x00265d24 in zend_print_variable (var=0xace8d0) at
/usr/local/cvs/php/php-src/Zend/zend_variables.c:171
#8  0x00267094 in zend_print_zval_r_ex (write_func=0x208fa0
<php_body_write_wrapper>, expr=0xace8d0, indent=16) at
/usr/local/cvs/php/php-src/Zend/zend.c:387
#9  0x00266dc8 in zend_print_zval_r (expr=0xace8d0, indent=16) at
/usr/local/cvs/php/php-src/Zend/zend.c:342
#10 0x002662c8 in print_hash (ht=0xace860, indent=12, is_object=1 '\001')
at /usr/local/cvs/php/php-src/Zend/zend.c:159
#11 0x00267074 in zend_print_zval_r_ex (write_func=0x208fa0
<php_body_write_wrapper>, expr=0xacea48, indent=8) at
/usr/local/cvs/php/php-src/Zend/zend.c:381
#12 0x00266dc8 in zend_print_zval_r (expr=0xacea48, indent=8) at
/usr/local/cvs/php/php-src/Zend/zend.c:342
#13 0x002662c8 in print_hash (ht=0xacde60, indent=4, is_object=0 '\0') at
/usr/local/cvs/php/php-src/Zend/zend.c:159
#14 0x00266ed4 in zend_print_zval_r_ex (write_func=0x208fa0
<php_body_write_wrapper>, expr=0xacc538, indent=0) at
/usr/local/cvs/php/php-src/Zend/zend.c:356
#15 0x00266dc8 in zend_print_zval_r (expr=0xacc538, indent=0) at
/usr/local/cvs/php/php-src/Zend/zend.c:342
#16 0x00165a10 in zif_print_r (ht=1, return_value=0xacea98, this_ptr=0x0,
return_value_used=0) at
/usr/local/cvs/php/php-src/ext/standard/basic_functions.c:2570
#17 0x0029d5ac in zend_do_fcall_common_helper (execute_data=0xbfffecb0,
op_array=0xacdda8) at /usr/local/cvs/php/php-src/Zend/zend_execute.c:2550
#18 0x0029dff4 in zend_do_fcall_handler (execute_data=0xbfffecb0,
op_array=0xacdda8) at /usr/local/cvs/php/php-src/Zend/zend_execute.c:2697
#19 0x00297a20 in execute (op_array=0xacdda8) at
/usr/local/cvs/php/php-src/Zend/zend_execute.c:1264
#20 0x002689bc in zend_execute_scripts (type=8, retval=0x0, file_count=3)
at /usr/local/cvs/php/php-src/Zend/zend.c:1051
#21 0x00209bf8 in php_execute_script (primary_file=0xbffff720) at
/usr/local/cvs/php/php-src/main/main.c:1641
#22 0x002aac60 in main (argc=2, argv=0xbffffc94) at
/usr/local/cvs/php/php-src/sapi/cli/php_cli.c:939


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

Reply via email to