Generally said, there should nothing be happening before the get_header()
call.
So initiate your class if is_page()
is true
via wp_head
action hook. Example:
add_action( 'wp_head', 'initiate_my_class' );
function initiate_my_class() {
if ( is_page() ) {
//code
}
}
Edit: As @AndrewBartel in his comment said you can globalize your variable or implement some kind of storage system via the class or another one.