title: Encode to JavaScript object, function get replaced
body: <p>I have an issue on highcharts project , charts options are saving in database . I am printing on chart using following code . Let me explain my issue using some sample code .</p>
  
  <pre><code>echo 'var options69 = '.$highcharts_json_options;
  echo PHP_EOL;
  echo 'var options69_func = '. json_encode( $functions);
  echo PHP_EOL;
  
  echo '$(document).ready(function() {';
  echo PHP_EOL;
  echo '      chart69 = new Highcharts.Chart( 
                  $.extend(true, options69, options69_func) 
              );';
  echo PHP_EOL;
  echo '});';
  </code></pre>
  
  <p>The issue is <code>$functions</code> not converts into correct JavaScript object . Here is example of code of  $functions </p>
  
  <pre><code>$functions = array(
      'chart' =&gt; array(
          'events' =&gt; array(
              'click' =&gt; "function(){inboxMenu(this.options);}"
          )
  
      ),
      'tooltip' =&gt; array(
          'formatter' =&gt; "function(){
              return '&lt;b&gt;'+ this.series.name + ':&lt;/b&gt;'+ this.y;
          }"
      )
  );
  </code></pre>
  
  <p>currently,  <code>json_encode( $functions)</code> outputs is </p>
  
  <pre><code>var options69_func = {
      "chart": {
          "events": {
              "click": "function(){inboxMenu(this.options);}"
          }
      },
      "tooltip": {
          "formatter": "function(){return '&lt;b&gt;'+ this.series.name + ':&lt;\/b&gt;'+ this.y;}"
      }
  }
  </code></pre>
  
  <p>But I need value <code>var options69_func</code> is like</p>
  
  <pre><code>var options69_func = {
      "chart": {
          "events": {
              "click": function(){
                  inboxMenu(this.options);
               }
          }
      },
      "tooltip": {
          "formatter": function(){
              return '&lt;b&gt;'+ this.series.name + ':&lt;\/b&gt;'+ this.y;
          }
      }
  }
  </code></pre>
  
  <p>Then only chart <code>click event</code> or <code>formatter</code>  works .. These values are coming from dynamically from server database . Could I add callback function to <code>json_encode</code> ?</p>
  
  <p>I added php generated js code to <a href="http://jsfiddle.net/u9W6X/" rel="nofollow">http://jsfiddle.net/u9W6X/</a></p>
  
  <p><strong>I won't like to using eval function.. on client side</strong></p>