Is Pass-by-Reference Faster in PHP (>= 5.0)?
In PHP, function parameters can be passed by reference, allowing functions to modify variables outside of their scope. While this is not intended for performance optimizations, it raises the question of whether the Copy On Write logic used in PHP affects performance for functions that do not modify their parameters.
Performance Tests
Tests involving 100,000 iterations of a function call with a string parameter of 20 kB revealed the following results:
For Functions That Read or Use the Parameter:
For Functions That Change the Parameter:
Conclusions
The above is the detailed content of Is Pass-by-Reference Slower Than Pass-by-Value in PHP for Functions That Don't Modify Parameters?. For more information, please follow other related articles on the PHP Chinese website!