The writing ( with foreach) of the keys of an array of objects to a new array produces fatal error

Ok i was a bit headblocked; with the following snippet i was able to get things working as expected:

    $media = abc_attachments( $post->ID );

    $arrayofids = array();
    foreach( $media as $key ) {
        array_push($arrayofids, $key->ID);
    }
    preprint($arrayofids);

Which lead to the following output:

Array
(
    [0] => 1072
    [1] => 1067
)