SteveFrost Posted October 18, 2009 Report Share Posted October 18, 2009 (edited) Hey,How can I set multiple variables in a class but not inside a function?I have the following code but I get the following error "Parse error: syntax error, unexpected T_VARIABLE". require_once('breadcrumbs.php');class vfrHome{ // Last ID to display in the table public $newsid = ""; public $url = $_SERVER["PHP_SELF"]; // <-- This code is the problem, I get the error when the variable is there but the code runs when it's not there. public function Breadcrumbs() { $breadcrumb = new breadcrumb; $breadcrumb->dirformat='ucwords'; $breadcrumb->showfile=FALSE; echo $breadcrumb->show_breadcrumb(); echo " > Recent News"; } } Thanks in advance,Steve Edited October 18, 2009 by SteveFrost Link to comment Share on other sites More sharing options...
justsomeguy Posted October 18, 2009 Report Share Posted October 18, 2009 You need to use a constructor for those. class vfrHome{ // Last ID to display in the table public $newsid; public $url; function __construct() { $this->newsid = ''; $this->url = $_SERVER['PHP_SELF']; } Link to comment Share on other sites More sharing options...
SteveFrost Posted October 18, 2009 Author Report Share Posted October 18, 2009 Thanks, that worked Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now