void SetCharInChunk(ref object chunk, int index, char ch)
{
AssertChunkObject(chunk);
if (chunk.GetType() == typeof(string))
{
var chars = ((string)chunk).ToCharArray();
chars[index] = ch;
chunk = chars;
}
else if (chunk.GetType() == typeof(byte[])) ((byte[])chunk)[index] = (byte)ch;
else if (chunk.GetType() == typeof(PhpString)) ((PhpString)chunk)[index] = ch;
else if (chunk.GetType() == typeof(char[])) ((char[])chunk)[index] = ch;
else throw new ArgumentException(chunk.GetType().ToString());
}