Post types in WordPress are not saved some where, they are registered everytime you request a page.
So to get all post types, you have to wait untill all post types are registered.
Normally, all post types are registered before the hook wp_loaded
is fired.
So change your code in something like this:
add_action( 'wp_loaded', 'my_get_all_types' );
function my_get_all_types() {
// if you want only custom post types use '_builtin'=> false in the arguments array
// 2nd argument should be 'objects' not 'object'
$cpts = get_post_types( array( '_builtin'=> false ), 'objects');
var_dump($cpts);
}