Get post or page id early

For mee it seems that the template_redirect hook worked. Thanks to Pieter Goosen.

Heres a solution that should work on earlier hooks:

function gdymc_object_exists( $object_id ) {

    return ( get_the_title( $object_id ) ) ? true : false;

}

function gdymc_objectID() {


    if( is_numeric( $_GET['page_id'] ) ):

        $object_id = $_GET['page_id'];

    elseif( is_numeric( $_GET['p'] ) ):

        $object_id = $_GET['p'];

    elseif( is_numeric( get_option( 'page_on_front' ) ) ):

        $object_id = get_option( 'page_on_front' );

    else:

        $object_id = 0;

    endif;


    return gdymc_object_exists( $object_id) ? $object_id : false;


}