PHP - How to fix undefined index error elegantly? : This is probably a generic question and 99% of the solutions I've read is to just use `isset` to be safe and verbose. However, I still think it's not that elegant and also a bit repetitive.

To understand my question a bit better, here's a general pattern on my code:

    class User {
      protected $name;
      protected $address;
    
      public function __construct() {
        ..
      }
    
      public function getName() {
        ..
      }
    
      public function setName() {
        ..
      }
    
      public function getAddress() {
        ..
      }
    
      public function setAddress() {
        ..
      }
    
      public static function buildObject(array $userProperties) {
        // Here, I'm building a user from an associative array.
        // If the developer passes in an array with missing name or address,
        // this will generate an undefined index error!
    
        $user = new User();
        $user->setName($userProperties['name']);
        $user->setAddress($userProperties['address']);
        return $user;
      }
    }

What I've tried so far:

 1. Adding in `isset()` checks on all set calls. This might not be a bad idea for this example, but I have some huge classes with a lot of properties and it looks and feels very repetitive.

 2. Making the array safe by looping over properties and setting them to null if they're not present in the array. This doesn't seem that bad in code but feels like a workaround.

 3. Using null coalesce operator `?? null`. This also feels repetitive and not that readable.

I'd prefer a simple solution that would not add much logic but will look elegant. I know it's preferable to have validation in here, but I'll encounter the same problem when handling optional fields.