0

I'm developing a Web App.
Until now the backend was JBoss 6.1 Application Server (Java EE).

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

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

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.

Snippet of "facade.php":

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

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.

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).

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.

Is my assumption correct?

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

1
  • 1
    Where the class is coming from shouldn't actually matter. And $sessionObj should already be passed by reference to the process methods. You sure there wasn't any error in your process method? Commented Jan 22, 2013 at 16:23

1 Answer 1

1

The definition of process method of Cases class should be

function process($internalObj, &$sessionObj) {
     [...]
}

the "&" in front of parameter marks that it's passed by reference

Sign up to request clarification or add additional context in comments.

1 Comment

u dont have to use & operator for passing objects...only for values...and passing values as references is not a good thing at all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.