I recently wrote a PHP wrapper class for a new API we are using and have been asked to setup a demo which makes use of it. Certain features can be called directly from PHP, however things such as performing actions on button clicks requires I make use of JS/AJAX.
As I already have an instance of the object in my main PHP file, can I pass this as a parameter to JS and then pass it through Ajax to my handler or is it necessary to establish two separate instances?
PHPandJavaScriptare living in 2 differents "environnements", you can pass plain old values from one world to the other one (integer, strings, boolean, array), but AFAIK you can't pass object reference. Additionnaly, for each call to a PHP page, a new context is created, which means you can't share a reference to an object between 2 calls to yourPHPfile (JavaScriptis not related to this in any way)