Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

String variable cannot stand on both sides of assignment


5 Posts   923 Views


Community Member, 4 Posts

29 October 2009 at 1:56am

Edited: 29/10/2009 1:59am

This is the code I'm using:

public function getAuthorsString($authors) {
$result = "";
if ($authors->exists())
foreach ($authors as $authorKey => $author) {
$result = $result."{$author->ForeName} {$author->SurName}, ";
$result = rtrim(trim($result), ",");
return $result;

The $authors variable is a DataObjectSet, and this line is the problem:

$result = $result."{$author->ForeName} {$author->SurName}, ";

I also tried:

$result .= "{$author->ForeName} {$author->SurName}, ";


$result = "{$result}{$author->ForeName} {$author->SurName}, ";

None of them work. But if I only assign without maintaining the last value, therefore ultimately returning only the last author:

$result = "{$author->ForeName} {$author->SurName}, ";

It works perfectly fine.
The error I'm getting is this:

error on line 33 at column 266: Encoding error

Please help me, I have no idea what to do.


Forum Moderator, 5513 Posts

29 October 2009 at 6:12pm

What are you trying to output? I assume you would want something like "John Smith, Joe Bloggs".

I'm also assuming that author isn't a Member object (because then you could just use $member->Name).

I would write that concatenation like

$result .= $author->ForeName . ' ' . $author->SurName ', ';


Community Member, 4 Posts

4 November 2009 at 10:44pm

Edited: 04/11/2009 10:49pm

EDIT: I deleted this post because I realized I was/am stupid >_> The error should be exactly what it said it was: A problem with the encoding in the database. I'm gonna investigate and post again.


Community Member, 4 Posts

4 November 2009 at 11:08pm

I have now changed all of my database to use utf8_general_ci, but that didn't work.
I use the assignment

$result .= $author->Name() . ', ';

and the Name() function looks like this:

public function Name() {
$result = $this->ForeName . ' ' . $this->SurName;
return $result;

The error seems to occur when a string pulled from the database hits a string defined in my code, but I have no idea what to do about it.


Community Member, 4 Posts

25 November 2009 at 11:40pm

I have now changed servers and am working with a fresh mysql database and look what happened! I can't even use simple strings anymore without producing an Encoding Error. My template looks like this (this is inside a <table>):

<% control CatalogueMedia %>
<td><% control Authors %>
$ForeName $SurName,
<% end_control %></td>
<% end_control %>

So i tried this, and the usual Encoding Error popped up. Then I replaced the inner <% control %> with static text, but $Title alone produced the error again! I then replaced $Title with static text and got exactly as many table rows as I have entries in my table. What is going on? I have no idea what to do at this point. Please help me!