May 9, 2013

In PHP, how do I call master class functions to different pages?

Gopinath’s Questions:

I have master class for the whole project. I need to call master class functions to different pages and methods as described below:

Master.php

class master{

    function login_parser(){

    }
}

Index.php

include('master.php')

function test(){
    $obj = new master();
}

function test2(){
    obj = new master();
}

I need to call object for every method. Is there any way to call an object in single time?

Yes, Instead of creating object everytime. Create on outside the functions on global scope.

include('master.php')
$obj = new master();

function test(){
    global $obj; //Now carry on
}

function test2(){
    global $obj;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!