Setting Array as private variable

Hi,

I am trying to do this:


class CategoryModel {

    private $array = array($_GET['rt']);
    private $addressArray = explode('/', $_GET['rt']);

}

Using Netbeans IDE and it doesn’t like it… I get red lines under both lines…

What am i doing wrong?

thanks

Perhaps if you’re using a standard text editor, but to be honest I never understood this convention when using a modern IDE. I can see all the details of a variable when using it anyway, so there’s no reason to have an odd naming preference.

Especially when all your class members are private, and exposed via a method interface. At that point, you’re not differentiating, you’re just making it harder to type. :slight_smile:

Thanks for your replies everyone :wink:

I got it working by looking at Scallio’s reply.

Thanks again

Looks like he already answered you, a wise coding convention is to add an underscore before private and protected methods/variables.

It’s a lot easier to detect later on!

Class Example {
	private $_array; 
	private $_addressArray; 

You can’t refer to another variable upon instantiation of a class variable

You can’t use functions for the creation of a class variable (but you can use array(), of course array() is a language construct and not a regular function).

Why not do the following?


class CategoryModel {
  private $array, $addressArray;

  public function __construct() {
    $this->array = array($_GET['rt']);
    $this->addressArray = explode('/', $_GET['rt']);
  }
}