In imagick 3.x (have not checked 2.x), this returns an imagemagick object and not a boolean.
<?php
$image = new Imagick('myanimation.gif');
$image = $image->optimizeImageLayers(); //Does not return a boolean!
$image->writeImage('optimized.gif');