I have a schema extention for users (extends modUser).
Some users (admin..) do not have that extended dataset.
For example, with this code (fragment of a output filter snippet):
$memberSchemaDef = '{"'.$class.'":{}}';
$memberUser = $modx->getObjectGraph('memberUser', $memberSchemaDef , $input);
if (isset($memberUser)) {
return $memberUser->{$class}->get($field); // <-- fails here
}
This code will fail once it’s executed on the admin user (or another user without the requested field).
Fatal error: Call to a member function get() on a non-object
Ofcourse - this makes sense, but how can I catch these errors? I don’t want thme to break the scripts.
Naturally, I can add specific exclution for admin user, but I’m looking for a generic solution. php try/catch will not help (as that would have needed to be implemented deeper in the core). isset/empty also will not, as $memberUser IS set for admin (as memberUser class extends modUser).
Idealy I’d like to make ->get return ’’ empty, instead of error..
Thanks.