Search code examples
phpphp-parse-error

OOP PHP unexpected T_VARIABLE


I am trying out OOP PHP and I seem to have run into a bit of a problem.

    class Connection
{   
    public $con = false;
    public $dbSelected = false;
    public $activeConnection = null;
    public $dataBaseName = "";
    function __contruct($dbUserName, $dbPassword, $server = "localhost")
    {
        $this->con = mysql_connect($server,$dbUserName,$dbPassword);
        if(!$this->con)
        {
            $this->activeConnection = false;
        }
        else
        {
            $this->activeConnection = true;
        }
    }
    // Says the error is on the line bellow
    public function dbConnect($dbName, $identifyer = $this->con)
    {
        $this->dbSelected = mysql_select_db($dbName, $identifyer);
        $this->dataBaseName = $dbName;
        if($this->dbSelected != true)
        {
            $this->connectionErrorReport();
        }
    }
    //... Class continues on but is unimportant. 

I get an Parse error: syntax error, unexpected T_VARIABLE in [path] on line 21

I have stared at it so long I really could use some help.


Solution

  • that's not a valid syntax. do this:

    public function dbConnect($dbName, $identifyer = null)
    {
        if ($identifyer === null)
          $identifyer = this->con;
        //...
    }