Sometimes getObject method doesn't work

Sometimes getObject doesn’t work where getIterator works (MODX Revolution 2.8.4-pl) with my custom components.

Example:

$id_shop = $modx->getOption('id_shop', $scriptProperties, '1');
//$modx->invokeEvent('OnHandleRequest');
if(!$ps17){
    $ps_database_host     = $modx->getOption('sconf_psdb17-host');
    $ps_database_charset  = $modx->getOption('sconf_psdb17-charset');
    $ps_database_name     = $modx->getOption('sconf_psdb17-name');
    $ps_database_prefix   = $modx->getOption('sconf_psdb17-prefix');
    $ps_database_username = $modx->getOption('sconf_psdb17-username');
    $ps_database_password = $modx->getOption('sconf_psdb17-pw');
    $ps17 = new xPDO('mysql:host=' . $ps_database_host .
           ';dbname=' . $ps_database_name .
           ';charset=' . $ps_database_charset,
       $ps_database_username,
       $ps_database_password );
    // load package for Prestashop
    $can_work_ps17 = $ps17->addPackage('presta17',MODX_CORE_PATH.'components/',$ps_database_prefix);    
}
$class_prefix = "Ps";

//getIterator method : works
$q_shop = $ps17->newQuery($class_prefix . 'Shop');
$q_shop->where(['id_shop' => $id_shop]);
$q_shop->limit(1);
$results_shop = $ps17->getIterator($class_prefix . 'Shop', $query);
foreach($results_shop as $shop){ $shop_name = $shop->get('name'); }


//getObject method : err 500
$results_shop = $ps17->getObject($class_prefix . 'Shop', ['id_shop' => $id_shop]);
$shop_name = $results_shop->get('name');

What exactly do you mean by “Sometimes getObject doesn’t work”?

Maybe you just have to check if getObject() returns a result, before trying to read the “name”:

$results_shop = $ps17->getObject($class_prefix . 'Shop', ['id_shop' => $id_shop]);
if ($results_shop){
	$shop_name = $results_shop->get('name');
}