Variable if post is sticky in functions.php

it may be easier than you thought. You’re coding is missing endline apostrophes:

foreach ( $posts as $post ) {
    if ( is_sticky() ) {
        $width="12"
    } else {
        $width="4"
    };

should be

foreach ( $posts as $post ) {
    if ( is_sticky() ) {
        $width="12";
    } else {
        $width="4";
    };