Using Strings Instead of Variables in WordPress Functions

The official WordPress documentation recommends registering CPTs this way

register_post_type( 'book', $args );

This works fine. But sometimes we want to register it via a variable. For example, to do it in a class. Here is an example


class Book_Post_Type {
	private string $type = 'book';

	public function __construct() {
		add_action( 'init', [ $this, 'register' ] );
	}

	public function register(): void {
		register_post_type( $this->type /* , $args */ );
	}
}

This all works as well. Thinking about extending this class, it looks good. We can use $this->type here and not duplicate this variable.

From an OOP perspective, this is not bad, and looks like a best practice, but it seems to me that from a WordPress perspective, this is not so.

Why is that? When we do not use the string directly, it will be much more difficult to find everything related to this CPT and where it is used. From a long-term observation point of view, it looks like doing a search on the project, you can find all functions related to this CPT.