title: Twig and error messages - is this normal?
body: <p>I've been testing Twig on localhost... the code here is the same as in <a href="https://stackoverflow.com/questions/14817159/twig-and-truncating-text">this question</a> but the query is different:</p>
  
  <pre><code>     &lt;?php
  // include and register Twig auto-loader
  include 'Twig/Autoloader.php';
  Twig_Autoloader::register();
  
  // attempt a connection
  try {
    $dbh = new PDO('mysql:dbname=world;host=localhost', 'root', 'mypass');
  } catch (PDOException $e) {
    echo "Error: Could not connect. " . $e-&gt;getMessage();
  }
  
  // set error mode
  $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  // attempt some queries
  try {
    // execute SELECT query
    // store each row as an object
    $sql = "SELECT manufacturer, model, modelinfo FROM automobiles WHERE id = '4' ";
    $sth = $dbh-&gt;query($sql);
    while ($row = $sth-&gt;fetchObject()) {
      $data[] = $row;
    }
  
    // close connection, clean up
    unset($dbh); 
  
    // define template directory location
    $loader = new Twig_Loader_Filesystem('templates');
  
    // initialize Twig environment
    $twig = new Twig_Environment($loader);
  
    // load template
    $template = $twig-&gt;loadTemplate('cars.html');
  
    // set template variables
    // render template
    echo $template-&gt;render(array (
      'data' =&gt; $data
    ));
  
  } catch (Exception $e) {
    die ('ERROR: ' . $e-&gt;getMessage());
  }
  ?&gt;
  </code></pre>
  
  <p>I have 3 records; I decided to query a non-existent record to see what Twig's error handling was like, as I was comparing Twig vs Smarty - out of interest, and for a project.
  This error message comes up:</p>
  
  <pre><code>Notice: Undefined variable: data in /Applications/MAMP/htdocs/mysite/twigtesting.php on line 42
  </code></pre>
  
  <p>Surely a notice saying 'Data not found' should happen or am I wrong here?
  Undefined variable data refers to:</p>
  
  <pre><code>      // set template variables
    // render template
    echo $template-&gt;render(array (
      'data' =&gt; $data
    ));
  </code></pre>
  
  <p>Why is this happening? I'm new to Twig, and using the latest build from their site, f that's relevant.</p>