Memo: if $factory is not object, 'instanceof' raises fatal error. To do fix it?