title: Calling a previously defined function in another (PHP)
body: <p>I've been reading answers on SO questioning the need for nested functions, but I still haven't figured out 1) why my code is erroneous and 2) how I can fix it to make what I wrote work OR change my script so it's more acceptable (to the parser but also to experienced developers). Let me mention that I am new to PHP OOP...</p>
  
  <p>The idea is I want to use a function that I previously defined in a whole lot of other functions, so it'll save me rewriting the code each time.</p>
  
  <p>Here's the faulty code, then, which throws a fatal error "Call to undefined function" pointing to the line in which I call selectMediaIds () within getMedia ()... (FYI I purposefully omitted the variable initialization, constructor, getters, setters, etc. to make my post more compact.)</p>
  
  <pre><code>&lt;?php
  
  class MediaManager {
  
  private function selectMediaIds (MObject $object) {
      $medias = array ();
      $req = $this -&gt; _db -&gt; query ('SELECT media_idMedia FROM mObject_has_media WHERE mObject_idmObject = ' . $object -&gt; id ());
      while ($data = $req -&gt; fetch (PDO::FETCH_ASSOC)) {
          $medias[] = $data;
      }
      $req -&gt; closeCursor ();
      return $medias;
  }
  
  public function getMedia (MObject $object) {
      $medias = array ();
      $mediaIds = selectMediaIds ($object);
      if ($mediaIds[0] != null) {
          foreach ($mediaIds as $id) {
              $req = $this -&gt; _db -&gt; query ('SELECT * FROM media WHERE idMedia = ' . $id);
              $req -&gt; fetch ();
              $medias[] = $req;
              //$medias[] = new Media ($req);
          }
      return $medias;
      }
  }}?&gt;
  </code></pre>
  
  <p>Thank you for your answer!</p>