PHP, Pass object from one object to another object per reference, when classes are in different files
<p>I'm developing a Web App.<br>
Until now the backend was JBoss 6.1 Application Server (Java EE).  </p>

<p>Now, with the same frontend, there should be another backend in PHP.<br>
As I like the structure of the Java Backend, I design a similar structure for the php backend.</p>

<p>EVERY request to the PHP backend goes to ONE entry, it's "facade.php", it is my front 
controller.  </p>

<p>The front controller (facade.php) handles the JSON input and other things and then there is a large switch statement. Every task (login, get event objects, ...) is transferred to another process class.  </p>

<p>Snippet of "facade.php":</p>

<pre><code>switch ($procClass) {
  case "lgi":
    require_once("classes/Login.php");
    $login = new Login();
    $resultMap = $login-&gt;process($internalObj, $sessionObj);
    break;
  case "cst":
    require_once("classes/Cases.php");
    $cases = new Cases();
    $resultMap = $cases-&gt;process($internalObj, $sessionObj);
    break;  
  .
  . 
  .
}
</code></pre>

<p>In the JBoss Java EE environment, when I am in an Stateless Session Bean and I do a local
look up to another Stateless Session Bean (different classes), the objects are handed 
to the method of the other class BY REFERENCE.</p>

<p>Now I know that, in PHP, when you are in the same class and you pass one object to another method of the same class, the object is passed per reference (or more accurately the reference is passed by value).</p>

<p>But, as in the example above, if I pass the "sessionObj" object from facade.php to the instance of another class (cases), which is in another file, it seems that it is NOT possible to pass objects per reference.</p>

<p>Is my assumption correct? </p>

<p>Is there another way to pass per reference in this situation (from object to object when the classes in separate files)?</p>
