title: How to execute a PHP closure which is stored (as string) in database
body: <p>I want some entities to execute extra code (which returns html), stored in their own data, in database. For this <strong>I am trying to store a closure in a field of the table</strong>, and execute it after retrieving it.</p>
  <p>The closure gives me the opportunity to encapsulate the script (in a scope) and execute it whenever I want after obtaining the database.</p>
  <p>The problem is that it doesn't work. Error: 'Fatal error: Uncaught Error: Call to undefined <code>function function () {...</code>.</p>
  <p>(Premise: I know that 'serialization of Closure is not allowed')</p>
  <p><strong>Example of the closure stored in database:</strong></p>
  <pre><code>function() {
      return '&lt;h1&gt;Today is '.date('d/m/Y').'&lt;/h1&gt;';
  };
  </code></pre>
  <p><strong>Retrieve data and execution of the closure:</strong></p>
  <pre><code>//example of retrieve
  $sql = &quot;SELECT field FROM table&quot;;
  $q = $link-&gt;query($sql);
  $row = $q-&gt;fetchRow();
  
  //execution, var must be contain the html processed in the closure
  $var = $row['field']();
  </code></pre>
  <p>Can anyone help me with the error or give me another idea to build this scenario?</p>
  <p>Many thanks.</p>