title: Passing php-objects to javascript
body: <p>I would like to know if it is possible to create a php-object and use it and its methods in my JavaScript.
  For example, I have the following php-script:</p>
  
  <pre><code>&lt;?php  
         class Foo
         {
             public function bar()
             {
                  //do something here
             }
         }
   ?&gt;
  </code></pre>
  
  <p>Then I could send an AJAX-request to the server and grab an instance of Foo:</p>
  
  <pre><code>  $.ajax({
      type: "POST",
      url: "path/to/Foo/Foo.php",
      data: {
          action: "get-object"
      },
      dataType: 'json',
      success : function(data){
          alert("My Foo object: "+data);
      },
      error : function(XMLHttpRequest, textStatus, errorThrown) {
          alert("Did not work");
      }
  });
  </code></pre>
  
  <p>Of course I would have to extend Foo.php a bit so that it returns me an instance of class Foo.</p>
  
  <p>I tried that and it did not work, my data variable is always empty.</p>
  
  <p>So is there another approach to get an instance of a php-class and call methods on it in Javascript?</p>