title: php call child class function from parent
body: <p>There are similar questions but none that are giving me a satisfactory answer.</p>
  
  <p>First off, here's my (simplified) code:</p>
  
  <pre><code>class classA; {
    function __construct() {
      ...do something...
      $this-&gt;init();
    }
  }
  
  class classB extends classA {
    function init {
      ...do something specific to this class which has to be done in the constructor...
    }
  }
  </code></pre>
  
  <p>When I call a new instance of the child function, the line "$this->init();" triggers the following error in the Apache error log:</p>
  
  <pre><code>[error] [client ip] PHP Parse error: syntax error, unexpected T_STRING, 
  expecting T_FUNCTION in ... on line... referrer:...
  </code></pre>
  
  <p>My reasoning is that I have things that I need to do in the constructor of the child class but I can't have a constructor there otherwise the constructor of the parent won't be processed. So I create the child, which pulls in the functions from the parent and executes the __constructor function. This function calls the (child's) init() function which has the child-specific logic and continues execution.</p>
  
  <p>My only guess is that it's calling a function that isn't read into memory yet - but I thought PHP read the entire file into memory before execution of the __constructor function. I've looked to see if there's a preload function but haven't found anything other than doing an include statement - but I feel this is the wrong track.</p>
  
  <p>Any help is greatly appreciated!</p>
  
  <p>EDIT: touching up some irrelevant details.</p>