Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php extending but with a new constructor...possible?

Tags:

php

I have a class:

class test {
    function __construct() {
        print 'hello';
    }
    function func_one() {
        print 'world';
    }
}

what I would like to do is a have a class that sort of extends the test class. I say 'sort of', because the class needs to be able to run whatever function the test class is able to run, but NOT run the construct unless I ask it to. I do not want to override the construct. Anyone has any idea how to achieve this?

like image 245
Patrick Avatar asked Feb 20 '26 05:02

Patrick


1 Answers

class test {
    function __construct() {
        print 'hello';
    }
    function func_one() {
        print 'world';
    }
}


class test_2 extends test {
    function __construct() {
        if (i want to) {
            parent::__construct();
        }
    }
}
like image 193
Amy B Avatar answered Feb 21 '26 19:02

Amy B