creating a constructor

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cmartin19
Forum Newbie
Posts: 5
Joined: Thu May 15, 2008 8:07 pm

creating a constructor

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: creating a constructor

Post by John Cartwright »

Code: Select all

function__construct()
vs

Code: Select all

function __construct()
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: creating a constructor

Post 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.
Post Reply