Jump to content

[SOLVED] setting a $_GET as a class constant


mattjones

Recommended Posts

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);
}
}

 

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'];
}

Archived

This topic is now archived and is closed to further replies.

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