I am relatively new to PHP. I have declared a class to hold some configuration information for my site. In this class i want to declare an associative array of paths. If I declare it thus:

[CODE]var $Paths = array
	(
	"HTML" => "HTML/",
	"NEWSIMAGES" => "HTML/Images/News/",
	"BRANDLOGOS" => "HTML/Images/BrandLogos/",
	"PRODUCTIMAGES" => "HTML/Images/Products/",
	"PRODUCTDOCUMENTS" => "HTML/Documents/Products/"
	);[/CODE]

all seems OK

But I thought i would be able to declare it as follows:

	$Paths = array();
	$Paths["HTML"] = "HTML/";
                $Paths["NEWSIMAGES"] = "HTML/Images/News";

However when I run this I get an error:

Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in . . . .

I thought both methods of declaring the array were equally valid. Or is the problem that I am declaring it within a class?

Help please I am terribly confused.

Thanks

Z

    Write the smallest and simplest script that demonstrates this problem. You are declaring it in a class, I suppose?

      Hi all,

      This is a double-post ... I have just answered the other one.

      Please delete one or the other.

      It is not good manners to double-post ... read the guidelines!

        Yes it is being declared in a class here is the entire code for the class:

        class ClassConfig
        {
        
        var $ClassName = "ClassConfig";
        
        var $SiteTitle = "Cyanotec Limited";
        var $TablePrefix = "Cyanotec_";
        
        // Paths
        
        $Paths = array();
        $Paths["HTML"] = "HTML/";
        $Paths["NEWSIMAGES"] = "HTML/Images/News/";
        $Paths["BRANDLOGOS"] = "HTML/Images/BrandLogos/";
        $Paths["PRODUCTIMAGES"] = "HTML/Images/Products/";
        $Paths["PRODUCTDOCUMENTS"] = "HTML/Documents/Products/";
        
        //	var $Paths = array
        //		(
        //		"HTML" => "HTML/",
        //		"NEWSIMAGES" => "HTML/Images/News/",
        //		"BRANDLOGOS" => "HTML/Images/BrandLogos/",
        //		"PRODUCTIMAGES" => "HTML/Images/Products/",
        //		"PRODUCTDOCUMENTS" => "HTML/Documents/Products/"
        //		);
        
        }

        The commented out code works but the other bit throws the error in my original message

        Thanks

        Z

          The error is caused by the missing keyword "var".

          You could do it like this, I suppose:

          var $Paths = array();
          
          function ClassConfig()
          {
              $this->Paths['HTML'] = 'HTML/';
              $this->Paths['NEWSIMAGES'] = 'HTML/Images/News/';
              $this->Paths['BRANDLOGOS'] = 'HTML/Images/BrandLogos/';
              $this->Paths['PRODUCTIMAGES'] = 'HTML/Images/Products/';
              $this->Paths['PRODUCTDOCUMENTS'] = 'HTML/Documents/Products/';
          }

          Or your other way.

            I see what you mean. The function ClassConfig is in effect a constructor for the class.

            Z

              Write a Reply...