kks_krishna Posted November 4, 2007 Share Posted November 4, 2007 HI, How can i declare a global variable to a class or a file? Quote Link to comment Share on other sites More sharing options...
bwochinski Posted November 4, 2007 Share Posted November 4, 2007 In a class global variables are declared at the beginning of the class outside of any functions. Not sure what you mean about the file... Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted November 4, 2007 Author Share Posted November 4, 2007 how can i delare outside and improt to all the classes. for example i have some commmon variables to be across all the files. so i want to delare those varibles in seperate files and use it on other files. how can i do that? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted November 4, 2007 Share Posted November 4, 2007 You can keep like this define("CONSTANT", "Hello world."); Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 5, 2007 Share Posted November 5, 2007 HI, How can i declare a global variable to a class or a file? i believe you dont know what your asking?? Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted November 5, 2007 Author Share Posted November 5, 2007 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. } Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 5, 2007 Share Posted November 5, 2007 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; } } Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted November 5, 2007 Author Share Posted November 5, 2007 thanks.. do we need to import Common.php? Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 5, 2007 Share Posted November 5, 2007 thanks.. do we need to import Common.php? Yep... just require_once('Common.php'); should do the trick... PhREEEk Quote Link to comment Share on other sites More sharing options...
kks_krishna Posted November 5, 2007 Author Share Posted November 5, 2007 Thanks. It helps me lot. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.