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? Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/ 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... Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384680 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? Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384696 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."); Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384699 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?? Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384702 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. } Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384812 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; } } Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384837 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? Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384844 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 Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384853 Share on other sites More sharing options...
kks_krishna Posted November 5, 2007 Author Share Posted November 5, 2007 Thanks. It helps me lot. Link to comment https://forums.phpfreaks.com/topic/75997-solved-how-to-declare-global-variables/#findComment-384875 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.