0

Imagine this code:

class Test
{
    public $result;

    public function makeSum($a,$b)
    {
        $sum = $a+$b;
        $this->result = $sum;
    }

}

In a webserver.

At same exact moment, two browsers call a page that performs that operation. First one has $a=1 and $b=2 and second one $a=5 and $b=4.

Are we sure that for first page $result will be 3 and for second one 9? Or is there possibility that result could be "wrong" for the page asking?

I'm talking in particular for PHP, but question can be general...

I think that will be never problems, but I would know if it's true and why.

Thank you!

  • 8
    yes, the requests are separated so they won't mix at all. If you want to share between requests you need to store the data in a database / file for example. All running code is never mixed. For the same user the session is also an exception, that is also stored in for example a file and shared between your own requests. – Luc Franken Mar 17 '15 at 6:57
1

They wont mix up. The function runs seperate on each page(browser). Wherever you declared the $a=1 and $b=2 will provide: 3. Same for the $a=5 and $b=4 will provide: 9. So you dont have to worry about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.