note 94576 modified in function.str-replace by danbrown
| From: | danbrown@php.net | Date: | Thu, 12 Nov 2009 17:31:00 +0000 |
| Subject: | note 94576 modified in function.str-replace by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162818@lists.php.net to get a copy of this message | ||
If you get a blank page when passing an object to str_replace() (relying on __toString() to convert
the object to a string) then you may need to force string context using (string), like so:
<?php
private function _load_vars($vars, &$source = false) {
if(!$source) $source =& $this->code;
foreach((array)$vars as $key => $var) {
$source = str_replace("{".$key."}", (string) $var, $source);
}
}
}
?>
I was running Ubuntu Server with PHP 5.2.6 and getting apache segfaults and mysterious blank pages
when $var happened to be certain objects.
--was--
If you get a blank page when passing an object to str_replace() (relying on __toString() to convert
the object to a string) then you may need to force string context using (string), like so:
private function _load_vars($vars, &$source = false) {
if(!$source) $source =& $this->code;
foreach((array)$vars as $key => $var) {
$source = str_replace("{".$key."}", (string) $var, $source);
}
}
}
I was running Ubuntu Server with PHP 5.2.6 and getting apache segfaults and mysterious blank pages
when $var happened to be certain objects.
http://php.net/manual/en/function.str-replace.php