Title: WP_Comment::__construct
Published: December 9, 2015
Last modified: April 28, 2025

---

# WP_Comment::__construct( WP_Comment $comment )

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#wp--skip-link--target)

Constructor.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#description)󠁿

Populates properties with object vars.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#parameters)󠁿

 `$comment`[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
required

Comment object.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#source)󠁿

    ```php
    public function __construct( $comment ) {
    	foreach ( get_object_vars( $comment ) as $key => $value ) {
    		$this->$key = $value;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-comment.php#L215)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-comment.php#L215-L219)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Comment::get_instance()](https://developer.wordpress.org/reference/classes/wp_comment/get_instance/)`wp-includes/class-wp-comment.php` |

Retrieves a [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/) instance.

  | 
| [get_comment()](https://developer.wordpress.org/reference/functions/get_comment/)`wp-includes/comment.php` |

Retrieves comment data given a comment ID or comment object.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_comment/__construct/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_comment%2F__construct%2F)
before being able to contribute a note or feedback.