Sugarquery - Dynamic Select Statement Failing

Hi team.

I am trying to build  a dynamic SugarQuery, the scenario is that I have an array of "fields" I want to use to create a dynamic select statement. For simplicity the $selectGenerator array below contains name and id.

Fullscreen
1
2
3
4
5
6
7
8
9
10
$sugarQuery = new SugarQuery();
$sugarQuery->from(BeanFactory::newBean($filename),array('team_security' => false));
foreach($selectGenerator as $field)
{
$field = "'" . trim($field) . "'";
print "select(array($field))" . "</br>";
$sugarQuery->select(array($field));
}
$sugarQuery->select(array('billing_address_street'));
$result = $sugarQuery->execute();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The above query only returns the "billing_address_street" field and not name and ID as expected.

If I manually updated the array to NOT use the variable and instead by hard coded (the exact same string) it works.

Fullscreen
1
2
3
4
5
6
7
8
9
10
$sugarQuery = new SugarQuery();
$sugarQuery->from(BeanFactory::newBean($filename),array('team_security' => false));
foreach($selectGenerator as $field)
{
$field = "'" . trim($field) . "'";
print "select(array($field))" . "</br>";
$sugarQuery->select(array('id'));
}
$sugarQuery->select(array('billing_address_street'));
$result = $sugarQuery->execute();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I've tried without the force quotes around name, and also without them, and it seems to always fail whenever I use a variable rather than hard coded. 

For instance I checked to ensure it was generating the same and my code generates the correct format which would be:

select(array('name'))
select(array('id'))

Has anyone else gotten around this or is this a bug?

Thanks,

Daniel