mattjones Posted December 8, 2008 Share Posted December 8, 2008 Hello i am trying to set a $_GET as a constant variable in a class to use in a few different methods in parent and child classes. This $_GET will be used to create a dynamic title using the URL and a few other things like page titles etc. The problem is i am not sure if i am allowed to do this or how it works as i am getting the following error: Parse error: syntax error, unexpected T_PUBLIC in /home/zqyrdetv/public_html/business_class.php on line 12 this is the code i am using: class business{ public $businesstype = $_GET['business']; public $region; public $businessname; private $con; function title() { //$business = $_GET['business']; $title = "Music & Media Business | UK $businesstype"; echo "$title"; } function database_connect() { $con = mysql_connect("localhost","*****","*****") or die ('Unable to connect to database!'); mysql_select_db("zqyrdetv_clientinfo", $con) or die ('Cannot find database!'); } function database_disconnect() { mysql_close($con); } } Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/ Share on other sites More sharing options...
JonnoTheDev Posted December 8, 2008 Share Posted December 8, 2008 Use static public $businesstype = $_GET['business']; Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/#findComment-709344 Share on other sites More sharing options...
mattjones Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/#findComment-709404 Share on other sites More sharing options...
mattjones Posted December 8, 2008 Author Share Posted December 8, 2008 sorry i thought it worked but it didnt still the same error Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/#findComment-709426 Share on other sites More sharing options...
JonnoTheDev Posted December 8, 2008 Share Posted December 8, 2008 pass the GET variable into one of your class methods and then set it public function setX($x) { $this->businesstype = $x; } Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/#findComment-709454 Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 You have to initialize variables in your constructor. <?php class business{ public $businesstype; public $region; public $businessname; private $con; public function __construct() { $this->businesstype = $_GET['business']; } Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/#findComment-709456 Share on other sites More sharing options...
mattjones Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks very much i created the __construct and changed all instances of $businesstype to $this->businesstype in all the methods i have used it in. Matt Quote Link to comment https://forums.phpfreaks.com/topic/136048-solved-setting-a-_get-as-a-class-constant/#findComment-709475 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.