Unexpected $end significa che non hai chiuso qualche struttura di controllo if, qualche ciclo while, foreach, for eccetera