How do I get the content type name using code? I'm working on Drupal 8 and I want to get content type machine name and label. Here is my code:

$cont_type = node_type_get_types();
foreach ($cont_type as $key =&gt; $value) {
  $label = $value-&gt;name;
  $machine_name = $key;
}


I get the following error message:


  Cannot access protected property Drupal\node\Entity\NodeType::$name


Hoe can I get the content type name?
To get a property, there is ConfigEntityBase::get(). Since ConfigEntityBase is a base class for NodeType, you can always use $value-&gt;get('name') to get the value of the name property.