#42052 [Fbk->WFx]: Trim doesn't trim correctly with null as charlist

From: Date: Fri, 20 Jul 2007 21:39:11 +0000
Subject: #42052 [Fbk->WFx]: Trim doesn't trim correctly with null as charlist
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-115259@lists.php.net to get a copy of this message
 ID:               42052
 Updated by:       jani@php.net
 Reported By:      martin at martinmoen dot com
-Status:           Feedback
+Status:           Wont fix
 Bug Type:         Strings related
 Operating System: Windows XP
 PHP Version:      5.2.3
 New Comment:

In any case, we're not changing the behaviour at this point. 
The function is clearly documented expecting a string as the charlist
parameter. 


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

[2007-07-20 16:40:34] jani@php.net

If I understood correctly, you want to be able to do 'trim($foo)' but
by passing 'trim($foo, null)'? 

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

[2007-07-20 13:27:46] martin at martinmoen dot com

Description:
------------
The trim function doesn't trim away whitespaces when giving it null
value in the charlist.

Reproduce code:
---------------
function array_trim($arr, $charlist=null)
{
	if (is_array($arr))
	{
		foreach($arr as $key => $value)
		{
			if (is_array($value)) $result[$key] = array_trim($value,
$charlist);
			else $result[$key] = trim($value, $charlist);
		}
		return $result; 
	}
}
var_dump(array_trim(array(' foo', 'bar ')));

Expected result:
----------------
array(2) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
}

Actual result:
--------------
array(2) {
  [0]=>
  string(4) " foo"
  [1]=>
  string(4) "bar "
}


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


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


Thread (4 messages)

« previous php.bugs (#115259) next »