By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,342 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Objects inside class.

P: 98
I have something like:
Expand|Select|Wrap|Line Numbers
  1. Class A{
  2.  
  3. ...other variables and methods...
  4.  
  5.     /*
  6.     * PRIVILIGES
  7.     */
  8.     public function getPriviliges(){
  9.         return $priviliges;
  10.     }
  11.  
  12.     public function setPriviliges(Priviliges $P){
  13.         $priviliges = $P;
  14.     }
  15.  
  16.     private $priviliges = new Priviliges();
  17. }
  18.  
and obviouly an other class "Priviliges".

Now, the bold line gives me the error "Static/Scalar constant expected". I'm using eclipse. (phpEclipse)

What am I doing wrong? I'm not really that seasoned in php. I'm a java programmer.
Sep 4 '08 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

You can only assign static values to members using the syntax you posted. Like say a string or a number.

Object instances should be created inside a method, typically inside the constructor, like:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. class obj
  3. {
  4.     private $object;
  5.  
  6.     public function __construct()
  7.     {
  8.         $this->object = new stdClass();
  9.     }
  10. }
  11. ?>
  12.  
Sep 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.