views:

46

answers:

1

Hi all!

I would like to know about static (class) field representation within PHP interpreter.

For example, when you load a class in Java, static fields will be associated with that Class object; that means two applications running same JVM (and same classloader) will have some kind of shared global variable ;)

I'm just wondering, if I use some kind of PHP accelerator/opcode caching, what is that really cached? Is it just compiled bytecode, or a piece of VM state (responsible for storing class objects)?

It's because I'm afraid of static fields/singleton objects sharing between requests, etc.

P.S.: I'm really a PHP newbie, so I'm very sorry if the question is way too dumb :)

+3  A: 

An opcode cache will not change anything : each PHP script is executed by its own process (or thread), in isolation from the others.

An opcode cache will only cache opcodes (the PHP equivalent of JAVA's bytecode), and will nor store not related to the current execution of the script -- i.e. not any kind of "VM state".

This means your static variables will exist in one version for each execution of your PHP script, even if that script is executed several times in parallel ; and using or not an opcode cache will not change a thing.

Pascal MARTIN
Thanks very much, i'm relieved now :)
Bubba88
You're welcome :-) *(I would add that if opcode caching did change something that important, it would be major problem)*
Pascal MARTIN