Page 1 of 1

creating a constructor

Posted: Fri May 23, 2008 6:17 pm
by cmartin19
Hi, I am having trouble creating a constructor.

The following constructor yields an error message: "Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION in /home/flowingb/public_html/admin/login_code.inc on line 13"

Line 13 happens to be function__construct()

class myclass
{
private $balance;
function__construct()
{
$this->balance = 100;
}
}

Thanks, cmartin19

Re: creating a constructor

Posted: Fri May 23, 2008 6:19 pm
by John Cartwright

Code: Select all

function__construct()
vs

Code: Select all

function __construct()

Re: creating a constructor

Posted: Fri May 23, 2008 6:20 pm
by Chris Corbyn
The word "private" yields the error because you're using PHP 4 instead of PHP 5 ;)

PHP 4 did not have visibility keywords. Use "var" instead.

EDIT | And the constructor won't run with __construct() in PHP4... use the class name instead.