Jump to content

Extended Class Constructors


Syphon

Recommended Posts

Here's my scenario:

Two classes, one is called the "baseclass" and the other is called "myClass" which extends the "baseclass".

When a new instance of "myClass" is created only the constructor in "myClass" is run. I thought OOP worked by the "baseclass" running it's constructor and then the class that extends it would run it's constructor. Am I doing something wrong or is this just the limitations of php?

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/99089-extended-class-constructors/
Share on other sites

nope, you need to do this:

 

<?php
  class myClass extends baseclass {
    function __construct() {
      parent::__construct();
//continue with myClass stuff
    }
  }
?>

 

it's detailed out here: http://us2.php.net/manual/en/language.oop5.decon.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.