Search code examples
phpoopoverloadingscope-resolution

PHP: Scope Resolution Operator & Overloading perfomance


I have 2 questions:

1) Is the Scope Resolution Operator (::) slow for static access (or slower than -> for an instantiated class)?

The name kinda suggests it has to "resolve" a scope so that's why I'm asking.

2) What about overloads, specifically __get() and __set()?

I have been avoiding their use because I heard they had an overall negative impact on perfomance.

Thanks in advance for any answers/advice.


Solution

    1. I benchmark object access at about 3% slower than static access.
    2. I benchmark __set($name, $value) at about 97% slower than a traditional setter like setBar($value) and about 321% slower than setting the property directly.