EllisLab/CodeIgniter — Issue #1065: Error when parsing objects
Author: qswks
Created: 2012-02-20 18:44:04+00:00
State: open

When you pass an object as $data to the [Tempalte Parser Class](http://codeigniter.com/user_guide/libraries/parser.html) an error is thrown for each object that couldn't be converted to string.

This snipplet:

```php
$data = array(
'name' => 'John Doe',
'details' => $stdClassObject,
'created' => $dateTimeObject
);

$this->load->library('parser');
$salutation = $this->parser->parse_string('Hi {name}', $data, TRUE);
```
Throws these errors:

ERROR - (date) --> Severity: 4096 --> Object of class stdClass could not be converted to string /path/to/codeigniter/system/libraries/Parser.php 101
ERROR - (date) --> Severity: 4096 --> Object of class DateTime could not be converted to string /path/to/codeigniter/system/libraries/Parser.php 101

Suggested patch (system/libraries/Parser.php - Line 101)

--- Parser.php 2012-02-20 19:40:04.000000000 +0100
+++ Parser.php.orig 2012-02-20 19:39:56.000000000 +0100
@@ -96,7 +96,7 @@
{
$template = $this->_parse_pair($key, $val, $template);
}
- else if (!is_object($val))
+ else
{
$template = $this->_parse_single($key, (string)$val, $template);
}