Question

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.

Was it helpful?

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.

OTHER TIPS

  1. For static method calls the engine has to resolve the class and the function. This costs two hash lookups.

    For instance method calls the engine does only one hash lookup.

    So instance method calls are a little faster than static method calls.

  2. __get and __set have the overhead of a property lookup (the engine checks if a property exists before calling __get or __set) plus the overhead of a method call.

    So this is twice times slower than using a getter or setter, and 3 or 4 times slower than accessing the property directly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top