Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Object-Oriented PHP Basics (Retired) Inheritance, Interfaces, and Exceptions Static Methods and Properties

static access :: and arrow -> operator

hi guys i just try to debug this code its said the when you use static key word you cannot access buy the arrow operator -> but i my case it's working ''' class Product{ public static $manufacturer = "big company";

public $name = 'default name';
public $price =0;
public $desc = 'default description';
function __construct($name, $price, $desc){
  $this->name = $name;
  $this->price = $price;
  $this->desc = $desc;
}
public function getInfo(){
  return "Product name: ".$this->name;
}
public function getMaker(){
  return  self :: $manufacturer;
}

} '''

1 Answer

Sorry, but I don't see you accessing $manufacturer using ->. Yes, you are accessing name, price and description, but they are not static.

sory for wrong post i just try to acces static property using arrow operator -> but still work on me i just make some research that when you declare static keyword you can use to access only using double colon : :

class Product{
    public static $manufacturer = "big company";
    public $name = 'default name';
    public $price =0;
    public $desc = 'default description';
    function __construct($name, $price, $desc){
      $this->name = $name;
      $this->price = $price;
      $this->desc = $desc;
    }
    public function getInfo(){
      return "Product name: ".$this->name;
    }
    public function getMaker(){
      return  self :: $manufacturer;
    }
}