class variables

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
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

class variables

Post 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...
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You can only assign constants there... Use the constructor to initialize those member values...
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: class variables

Post 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;
}
(#10850)
Post Reply