From:             
Operating system: Linux (though it doesnt matter)
PHP version:      5.3.2
Package:          Scripting Engine problem
Bug Type:         Feature/Change Request
Bug description:Perhaps there should be a way to explicitly dereference in PHP

Description:
------------
It seems that the part of PHP that is responsible for minimizing the
footprint of passing around data, at least within an object, does too good
of a job, and the lack of an explicit "dereference" or a forced, perhaps
recursively-acting "assign by value" operator creates an issue where a
programmer can not explicitly dereference the data behind that referenced
value, that, for example, is being pushed into an array, would lead to an
array of referenced values (with vales that would not be what you would
predict them to be)



So the code: MyResult is a class meant to unify access to mysqli result
data access between query and prepared statement. SQL is just a couple of
commands to set up the testing environment (test table). The MyTest opens a
connection and tries to get the data. Query results, which are passes back
the array returned from mysqli's result fetch_array function are properly
dereferenced in getArray method. The prepared statement results that are
passed back as $this->bind_arr are not properly dereferenced, and get added
to $ret as references, resulting in the final array that is filled with
both id and value filled with the latest data set in the $this->bind_arr,
which leads me to believe that this is a dereferencing issue, in this case
id=3 and value=val3. If you add a print_r line to the while loop, you will
see that with stored procedure results, every new result is passed back,
all the values are updated to that result set.



Hopefully this is short enough to describe the issue,



-- Alex

Test script:
---------------
MyResult.php

http://pastebin.com/qJRWySks



SQL:

create table test_table (id int not null auto_increment primary key, value
varchar(8));

insert into test_table (`value`) values ("val1"), ("val2"), ("val3");



MyTest.php

http://pastebin.com/AV6B79Vk

Expected result:
----------------
Prepared statement

Array ( [0] => Array ( [id] => 1 [value] => val1 ) [1] => Array ( [id] => 2
[value] => val2 ) [2] => Array ( [id] => 3 [value] => val3 ) [3] => 



Query

Array ( [0] => Array ( [id] => 1 [value] => val1 ) [1] => Array ( [id] => 2
[value] => val2 ) [2] => Array ( [id] => 3 [value] => val3 ) [3] => 

Actual result:
--------------
Prepared statement

Array ( [0] => Array ( [id] => 3 [value] => val3 ) [1] => Array ( [id] => 3
[value] => val3 ) [2] => Array ( [id] => 3 [value] => val3 ) [3] => )



Query

Array ( [0] => Array ( [id] => 1 [value] => val1 ) [1] => Array ( [id] => 2
[value] => val2 ) [2] => Array ( [id] => 3 [value] => val3 ) [3] => 

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51327&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=51327&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=51327&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=51327&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=51327&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51327&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=51327&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=51327&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=51327&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=51327&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=51327&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=51327&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=51327&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=51327&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=51327&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51327&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51327&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=51327&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=51327&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=51327&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=51327&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=51327&r=mysqlcfg

Reply via email to