Page 1 of 1

class variables

Posted: Mon Apr 17, 2006 4:37 pm
by shiznatix
I have this:

Code: Select all

class boaddManageAdverts
{
    var $so;
    var $lang;

    var $langs;

    var $cities     = $GLOBALS['cities']; //line 13 right here
    var $objects    = $GLOBALS['objects'];
    var $city_areas = $GLOBALS['city_areas'];
    var $included   = $GLOBALS['included'];
    var $counties   = $GLOBALS['counties'];
    var $stoves     = $GLOBALS['stoves'];
and I get this:
Parse error: parse error, unexpected T_VARIABLE in /var/www/list/class/manageAdverts/class.boaddManageAdverts.php on line 13
I dont see it. am I just being blind? I could have sworn this code worked like yesterday...

Posted: Mon Apr 17, 2006 4:41 pm
by timvw
You can only assign constants there... Use the constructor to initialize those member values...

Posted: Mon Apr 17, 2006 4:46 pm
by shiznatix
thanks!

Re: class variables

Posted: Mon Apr 17, 2006 5:21 pm
by Christopher
Urgh ... how about making clean dependencies and a real interface like:

Code: Select all

class boaddManageAdverts
{
    var $so;
    var $lang;

    var $langs;

    var $cities     = '';
    var $objects    = '';
    var $city_areas = '';
    var $included   = '';
    var $counties   = '';
    var $stoves     = '';

function boaddManageAdverts ($cities, $objects, $city_areas, $included,  $counties, $stoves) {
    $tthis->cities     = $cities;
    $tthis->objects    = $objects;
    $tthis->city_areas = $city_areas;
    $tthis->included   = $included;
    $tthis->counties   = $counties;
    $tthis->stoves     = $stoves;
}