Access PHP method from HTML onclick event
<p>I'm trying to develop a webpage (<code>menu.php</code>) which has a <code>&lt;div&gt;</code> when clicked accesses "one" of the many methods in the <code>stock-c.php</code>. The code I have developed as follows:</p>

<h3>menu.php</h3>

<pre><code>&lt;?php 
require_once '../control/stock-c.php';
?&gt;
&lt;html&gt;
&lt;body&gt;
    &lt;div onclick="&lt;?php $obj=new StockController(); $obj-&gt;checkAccessRights();?&gt;"&gt;  //I know this is a wrong implementation
       //some code here
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<h3>stock-c.php</h3>

<pre><code>class StockController{
    public function checkAccessRights(){
        //some code here
    }
    public function getPID(){
        //some code here
    }
}
</code></pre>

<p>I know <code>menu.php</code> file's <code>onclick</code> event is a wrong implementation.</p>

<p>Since there will be other situations that I will need to call other methods (like <code>getPID()</code>) in other PHP web pages, I'm not sure if using jQuery to create an AJAX call on the <code>onclick</code> event in <code>menu.php</code> to access an "altered" <code>stock-c.php</code> file such as:</p>

<pre><code>class StockController{
    $obj=new StockController();
    $obj-&gt;checkAccessRights();

    public function checkAccessRights(){
        //some code here
    }
    public function getPID(){
        //some code here
    }
}
</code></pre>

<p>which was suggested in <a href="https://stackoverflow.com/questions/21304054/how-to-call-php-function-in-a-class-from-html-button-click">How to Call PHP Function in a Class from HTML Button Click</a> would work as this breaks my ability to access the other function. I just am not sure what alternatives I have. Any help will be appreciated.</p>