plus simplement : 
$g->firstname = (empty($infogrp["givenname"] )) ? $infogrp["cn"] : $infogrp["givenname"];