Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 973425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:16:37+00:00 2026-05-16T03:16:37+00:00

I wonder what is the speed price of using inheritance in php.

  • 0

I wonder what is the speed price of using inheritance in php.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:16:38+00:00Added an answer on May 16, 2026 at 3:16 am

    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:

    <?php error_reporting(-1); ini_set('memory_limit', '1024M');
    
    // Create classes A to Z with each class extending the previous class
    class A { public function fn() { return TRUE; } }
    $previous = 'A';
    foreach(range('B','Z') as $klass) {
        eval(sprintf('class %s extends %s{}', $klass, $previous));
        $previous = $klass;
    }
    
    // create results for non-inheriting class A
    function A_is_a()       { return is_a(new A, 'A'); }
    function A_get_class()  { return get_class(new A); }
    function A_get_parent() { return get_parent_class(new A); }
    function A_call_fn()    { $a = new A; return $a->fn(); }
    
    // create results for Z that inherits from Y ... that inherits from A
    function Z_is_a()       { return is_a(new Z, 'A'); }
    function Z_get_class()  { return get_class(new Z); }
    function Z_get_parent() { return get_parent_class(new Z); }
    function Z_call_fn()    { $z = new Z; return $z->fn(); }
    
    for($i=0;$i<10000;$i++) A_is_a();
    for($i=0;$i<10000;$i++) A_get_class();
    for($i=0;$i<10000;$i++) A_get_parent();
    for($i=0;$i<10000;$i++) A_call_fn();
    
    for($i=0;$i<10000;$i++) Z_is_a();
    for($i=0;$i<10000;$i++) Z_get_class();
    for($i=0;$i<10000;$i++) Z_get_parent();
    for($i=0;$i<10000;$i++) Z_call_fn();
    

    Results on my machine using PHP5.3.3 CLI and Zend Debugger

    Function     Calls  Av. Own   Own Time  Others    Total
    
    A_is_a       10000  0,000003  0,025626  0,000000  0,025626
    A_get_class  10000  0,000002  0,022033  0,000000  0,022033
    A_get_parent 10000  0,000002  0,020804  0,000000  0,020804
    A_call_fn    10000  0,000003  0,034949  0,012274  0,047223
    
    Z_is_a       10000  0,000002  0,024436  0,000000  0,024436
    Z_get_class  10000  0,000003  0,028833  0,000000  0,028833
    Z_get_parent 10000  0,000002  0,022144  0,000000  0,022144
    Z_call_fn    10000  0,000003  0,033359  0,012549  0,045908
    

    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_a function call, but seriously, if any of your productive code extends 1000 classes you got bigger problems 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder, using Eclipse's PyDev plugin , how come documentation does not always show
I am developing a pet project with Clojure, but wonder if I can speed
I was wondering how to speed up my iPad application using OpenGLES 2.0. At
What are the recommended approaches to using Thread.sleep() to speed up tests. I am
I wonder about the best approach for measuring the speed of loading pages of
I wonder if i change all my regular ForEach to Parallel.ForEach, will speed up
Hi I Wonder why usual graphic speed is so much slower than VB6 in
wonder why when I export my project to *.air and I install it on
wonder what's wrong <table id=tblDomainVersion> <tr> <td>Version</td> <td>No of sites</td> </tr> <tr> <td class=clsversion>1.25</td>
wonder whether someone can help me with the following one... I have a struct

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.