title: Best practice for passing variable outside of the function
body: <p>I'm using <a href="https://github.com/stil/gif-endec" rel="nofollow noreferrer">gif-endec</a> to manage my gif images. And I want to get the duration of each frame of the gif. Currently I'm using the scripts below :</p>
  
  <pre><code>$gifStream = new FileStream("myfile.gif");
  $gifDecoder = new Decoder($gifStream);
  Global $gifDurations;
  
  $gifDecoder-&gt;decode(function (FrameDecodedEvent $event) {
    global $gifDurations;
    $gifDurations[] = $event-&gt;decodedFrame-&gt;getDuration();
  });
  </code></pre>
  
  <p>The scripts works fine and the output is :</p>
  
  <pre><code>array(3) { [0]=&gt; int(200) [1]=&gt; int(200) [2]=&gt; int(200) }
  </code></pre>
  
  <p>But I would like to know is there a better way to get the same result? I tried to use <code>return</code>, but it can't get the result. Or I just didn't do it in a proper way...</p>
  
  <p>Please let me know if there is a better solution...</p>
  
  <p>P.S. I tried to use <a href="https://github.com/Sybio/GifFrameExtractor" rel="nofollow noreferrer">GifFrameExtractor</a>. It is simple to use, but it can't get the correct duration time.</p>