[eluser]Xeoncross[/eluser]
Ok, I think that if you iterate though an object it automatically create the values by reference. The problem was that I wasn't returning the value in a function.
Here is what I was doing.
Code:
foreach($xml->something as $key => &$item) {
sanitize_text($item);
//or
//$item = saintize_text($item);
}
Nither of those worked - but it was the fault of my function! I was trying to do it like this:
Code:
function sanitize_text(&$text){
//for file_names_make_it_underscore
trim(str_replace('__', '_', preg_replace("/([^a-z0-9\.]+)/i", '_', $text)));
}
When it should have been like this:
Code:
function sanitize_text($text){
//for file_names_make_it_underscore
return trim(str_replace('__', '_', preg_replace("/([^a-z0-9\.]+)/i", '_', $text)));
}
Ok, so when iterating over an object using a foreach php does it by ref. But PHP 5 no longer plays nice with function arguments by reference.
It also seems to be impossible to "unset" an property of an object with unset(). This might have to do with the variable scope unset deals with.
Code:
foreach($xml->something as $key => $item) {
unset($item);
//but the var still exists...
$item = 'new';
//Yet this modifies the value of $xml->something[$key]!?
}
What's going on!?