| Bug #14892 | Notice: Array to string conversion in /home/clockwerx/pear/File_SearchReplace/S |
| Submitted: |
2008年10月27日 05:28 UTC |
| From: |
doconnor |
Assigned: |
doconnor |
| Status: |
Closed |
Package: |
File_SearchReplace (version CVS) |
| PHP Version: |
5.2.4 |
OS: |
| Roadmaps: |
(Not assigned) |
[2008年10月27日 05:28 UTC] doconnor
(Daniel O'Connor)
Description:
------------
Unit tests produce an array to string E_NOTICE
Test script:
---------------
pear run-tests
Expected result:
----------------
Tests pass
Actual result:
--------------
60) /home/clockwerx/pear/File_SearchReplace/tests/04normal_bof.phpt
--- Expected
+++ Actual
@@ -1,10 +1,15 @@
+Notice: Array to string conversion in /home/clockwerx/pear/File_SearchReplace/SearchReplace.php on line 265
+
+Notice: Array to string conversion in /home/clockwerx/pear/File_SearchReplace/SearchReplace.php on line 265
+
+Notice: Array to string conversion in /home/clockwerx/pear/File_SearchReplace/SearchReplace.php on line 265
<?php
// +-----------------------------------------------------------------------+
-// | Copyprotected. Richard Heyes |
+// | Array Richard Heyes |
// | All rights reserved. |
// | |/**
// +-----------------------------------------------------------------------+
-// | Copyprotected. Richard Heyes |
+// | Array Richard Heyes |
...
*
* Search and Replace Utility
Comments
[2008年10月27日 12:51 UTC] techtonik
(anatoly techtonik)
[2008年10月27日 13:19 UTC] doconnor
(Daniel O'Connor)
The test case (04normal_bof.phpt) covers
str_replace('string', array('one','two', 'three'))
http://php.net/str_replace says:
If search and replace are arrays, then str_replace() takes a value from each array and uses them to do 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.
... which is why it raises the array to string conversion error.
[2008年10月27日 13:19 UTC] doconnor
(Daniel O'Connor)
(and that's what old code covered off, this was just shifting it to elsewhere)
[2008年10月27日 14:27 UTC] techtonik
(anatoly techtonik)
It doesn't seems as a bug in a library, but rather in test-suite that was designed for PHP4. It is better to accept E_NOTICE as appropriate warning to review the code for those who dared to supply meaningless arguments to function.
[2008年10月27日 14:36 UTC] doconnor
(Daniel O'Connor)
If you look at the patch, you can see I just shifted
$local_find = array_values((array) $this->find);
$local_replace = (is_array($this->replace)) ? array_values($this->replace) : $this->replace;
higher up - the php4 code was already explicitly dealing with this situation; so that smells like this E_NOTICE has been around for a while.
http://pear.php.net/bugs/patch-display.php?bug=14892&patch=fix-tests&revision=latest
[2008年10月27日 14:43 UTC] techtonik
(anatoly techtonik)
Well, ok. Go on. It is too late to revert it back.
[2008年10月27日 14:50 UTC] doconnor
(Daniel O'Connor)
This bug has been fixed in CVS.
If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).
If this was a problem with the pear.php.net website, the change should be live shortly.
Otherwise, the fix will appear in the package's next release.
Thank you for the report and for helping us make PEAR better.
Committed in Rev 1.6
Thanks for the review/feedback :)
[2008年10月31日 17:04 UTC] doconnor
(Daniel O'Connor)
Missed one additional occurrence of this style of problem (Fixed in Rev 1.23)