Jump to content

[SOLVED] How to declare global variables?


kks_krishna

Recommended Posts

Let me put it clear.

For example I have two files : detail.php and common.php

 

Here detail.php is the file where we write the logic. Common.php is used for delaring all the common variables used across the files. take one scenario, i want to display 10 rows per page, so i will add one variable as rows_per_page = 10; in common.php. I want to use this varible in detail.php bcos it can be used in other files also. so did like this:

 

common.php

-----------

class{

  rows_per_page=10;

}

 

detail.php

---------

 

class Detail{

    function m(){

        // i want to use that variable here. how can i do that.

    }

 

 

Pleaes help me.

 

}

Link to comment
Share on other sites

common.php

 

//Class not needed here...
/*
class{
   rows_per_page=10;
}
*/

//instead... and you can use '10' (single quoted) if you want it a string

define('_ROWS_PER_PAGE', 10);

 

detail.php

 

class Detail{
    function m(){
        echo "Rows Per Page = " . _ROWS_PER_PAGE;
    }


}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.