Altering (adding) field value when is unknown
For nodes, like for every content entity, you can use code similar to the  following one to check if a Field API field(*) exists.

if ($node-&gt;hasField('field_version')) {
  // The node has that field; access it with $node-&gt;hasField('field_version').
}


A more generic code that would work for either Field API fields or non-field properties would be similar to the following one.

if (isset($node-&gt;field_version)) {
  // The node has that field/property; access it with $node-&gt;field_version.
}


* I am using the terminology used in a comment for code in ContentEntityBase::__isset().

// "Official" Field API fields are always set. For non-field properties,
// check the internal values.
return $this-&gt;hasField($name) ? TRUE : isset($this-&gt;values[$name]);