From:             narf at bofh dot bg
Operating system: Irrelevant
PHP version:      Irrelevant
Package:          Unknown/Other Function
Bug Type:         Feature/Change Request
Bug description:str_replace() to accept search as a string while replace is an 
array

Description:
------------
---
>From manual page:
http://www.php.net/function.str-replace#refsect1-function.str-replace-parameters
---

> If search and replace are arrays, then str_replace() takes a value from
each array and uses them to search and replace on subject. If replace has
fewer values than search, then an empty string is used for the rest of
replacement values. If search is an array and replace is a string, then
this replacement string is used for every value of search. The converse
would not make sense, though.

That last sentence is what bothers me, as I have a use case where it DOES
make sense. In the patch below (line 646), I assumed that this is an
accepted behavior:

https://github.com/EllisLab/CodeIgniter/commit/10cbdf091b3cdbc72847dad28a1dce03a92119b6

To shortly explain what the patched method does - it's basically a pseudo
prepared statement compiler. It takes an SQL query and an array of values
and then replaces each occurence of '?' (default value for
$this->bind_marker) with the corresponding (by position) element from the
input array.

Test script:
---------------
<?php
$query = 'UPDATE `table_name` SET `field1_name` = :? WHERE `field2_name` =
:?';
$bind_marker = '?';
$bind_values = array("'foo'", "'bar'");
echo str_replace($bind_marker, $bind_values, $sql);

Expected result:
----------------
UPDATE `table_name` SET `field1_name` = 'foo' WHERE `field2_name` = 'bar'

Actual result:
--------------
PHP Notice:  Array to string conversion in php shell code on line 5
UPDATE `table_name` SET `field1_name` = Array WHERE `field2_name` = Array


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

Reply via email to