I wonder what is the speed price of using inheritance in php.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Inheritance is a key element of OOP. You should not concern yourself about any speed impact it might have. You can (and should) favor composition and aggregation over inheritance, but if your design needs inheritance, you use it. Anything else would be like saying you wanna play baseball without a bat. Inheritance is part of the game.
Anyway, here is a little something to run with your favorite profiler:
Results on my machine using PHP5.3.3 CLI and Zend Debugger
Disclaimer: Note that results may vary on your machine and also note that isolated benchmarks are usually pointless anyway, especially when it is about µ-optimizations like this. You could change the code to extend 1000 classes and then you will see a difference in the
is_afunction call, but seriously, if any of your productive code extends 1000 classes you got bigger problems 😉