Cant access constants defined outside class in it

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
pankajphartiyal
Forum Newbie
Posts: 1
Joined: Fri Jan 08, 2010 3:01 am

Cant access constants defined outside class in it

Post by pankajphartiyal »

Parse error: syntax error, unexpected '.', expecting ',' or ';' in G:\workspace\learningPHP\PhotoGallery\includes\photograph.php on line 6
I am getting this error on line in file logfile.php


logfile.php is

Code: Select all

<?php
[color=#FF0000]require_once("../../includes/initialize.php");[/color]
$logpath=SITE_ROOT.DS."logs".DS."log.txt";     //this is working fine
...........
 
photograph.php is

Code: Select all

<?php
 
class Photograph {
        ............
        ............
        [color=#FF0000]public $target_dir=SITE_ROOT.DS."public".DS."images";[/color]
        public $errors=array();
SITE_ROOT and DS are constants defined in a file initialize.php which looks like

initialize.php is

Code: Select all

defined('DS')   ?   null    :   define('DS',DIRECTORY_SEPARATOR);
    defined('SITE_ROOT')    ?   null    :   define('SITE_ROOT',$_SERVER['DOCUMENT_ROOT'].DS."PhotoGallery");
    .......
    require_once(LIB.DS."config.php");
    require_once(LIB.DS."functions.php");
    require_once(LIB.DS."session.php");
    require_once(LIB.DS."database.php");
    require_once(LIB.DS."user.php");
    require_once(LIB.DS."photograph.php");

Cant I access constants defined outside class inside it?
I have also have some constants defined inside config.php which u cn see is included in initialize.php, and whose constants are working fine inside any classes.
Plz help.
Thnx in advance..
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Cant access constants defined outside class in it

Post by VladSun »

You can't use expressions, functions, etc. to initialize object properties in its class definition - put the initialization into the constructor.
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply