How do I access the loaded comment object? I'm trying to access the comment field value in controller. With the following code I'm able to access the particular comment object.

$comment = \Drupal::entityManager()-&gt;getStorage('comment')-&gt;load($commentID);


When I try print_r for the $comment variable, I can see the fully loaded comment object.


I understand I cannot access the values by traversing the object since the values are protected. I tried $comment-&gt;get('subject')-&gt;value function, this time its looping and doesn't return any results.

How do I achieve retrieving the value of specific fields associated with comment entity?
It is better to use kint() function of the devel module for debugging entities because you will get also a list of available public methods.

You cannot get all comment fields values by looping them as different fields have different array result structure. 

Using $comment = \Drupal::entityTypeManager()-&gt;getStorage('comment')-&gt;load($commentID) you get full comment object.

$comment-&gt;get('comment_body)-&gt;value you get comment body value as it uses some text format (eg. full html). 

You also can covert comment object to array $comment = $comment-&gt;toArray().