1

For instance I have the following class

class myClassName{

    function funtionOne(){

        $a = '123';
        $b = '456';
        $c = '789';

        $d = 'var_value';
        $e = 'var_value';
        $f = 'var_value';
    }

    function funtionTwo(){
        $a = '123';
        $b = '456';
        $c = '789';

        $g = 'var_value';
        $h = 'var_value';
        $i = 'var_value';
    }

}

As you can see the variables $a, $b, $c are in both methods. My question is: How can I extend a method so get something like this:

class myClassName{

    function funtionABC(){
        $a = '123';
        $b = '456';
        $c = '789';
    }

    function funtionOne(){

        include functionABC's content here

        $d = 'var_value';
        $e = 'var_value';
        $f = 'var_value';
    }

    function funtionOne(){

        include functionABC's content here

        $g = 'var_value';
        $h = 'var_value';
        $i = 'var_value';
    }

}

Note: I do not want to return anything from the function, just want to retrieve the content, as you would with an include() or a trait. Thank you.

Diego Poveda
  • 110
  • 5

1 Answers1

1
class myClassName{
    public $a, $b, $c;

    function Init_funtionABC(){
        $this->a = '123';
        $this->b = '456';
        $this->c = '789';
    }

    function funtionOne(){

        Init_funtionABC();

        //you can access $this->a , $this->b , $this->c here

        $d = 'var_value';
        $e = 'var_value';
        $f = 'var_value';
    }

    function funtionOne(){

        Init_funtionABC();

        //you can access $this->a , $this->b , $this->c here

        $g = 'var_value';
        $h = 'var_value';
        $i = 'var_value';
    }

}
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71