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); } } 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']; 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 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 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; } 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']; } 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 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
Archived
This topic is now archived and is closed to further replies.