Hi Stas,

On Tue, May 12, 2009 at 7:24 PM, Stanislav Malyshev <s...@zend.com> wrote:
> Hi!
>
>> Apologies, I'm not familiar with run-time inheritence in PHP. My
>> understanding was that when a classes source code is compiled, its
>> parent classes must be known. When is this not the case? Must it be
>> known for the class' first instantiation?
>
> No, the problems here are different. The process works as follows:
> 1. Class X source is compiled.
> 2. "X" is added to the class table
> 3. Class Y (extends X) source is compiled.
> 4. Since Y extends X, methods of X are added to methods of Y
> 5. "Y" is added to the class table
>
> Now, adding bytecode caching. Bytecode caching replaces steps 1 and 3 with
> "loaded from cache" - however since the identity of X can change between
> requests, what is stored for step 3 can not bind to X as it is now - for
> that there's step 4 which is executed at runtime, when the line where class
> is defined is executed. That means static table describing class Y can exist
> only after step 4, and it is not cacheable beyond the bounds of one request.

Great explanation, thank you. As far as terminology goes, this is
still static inheritance, as you cannot change a class' parent after
it has been "set" in a request. Run-time inheritance is where it can
change, for example in Javascript where an object's prototype can be
changed. I think you could do lookup caches (ie the OP's patch) either
way, but its probably cheaper with static inheritance.



> However, if we now are compiling the code such as:
> $a->foo();
> we meet with following challenges:
> 1. We do not know what class $a is (suppose it's X, but in most cases we
> won't know that)
> 2. If we did, we do not know what class X is (definition, as opposed to just
> name) at the compile time (it could be defined later)
> 3. If we knew what class X definition is at compile time, the above would
> preclude us from generating any code that binds to that definition since
> such code would not be cacheable.
>
> These are three independent challenges, without overcoming each of them I do
> not see how virtual table would be helpful.

Yes. As I replied to Dmitry, I clearly wasn't thinking when I
suggested this. FYI, I do type-inference on PHP, and the types here
are difficult to calculate in the general case.

Thanks,
Paul



-- 
Paul Biggar
paul.big...@gmail.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to