I cant figure out why im getting an error with this code.. can someone help me out?

error is : Fatal error: Cannot access empty property

class Product
{
	var $parent_category;
	var $name;

function Product($new_name, $new_parent)
{
	$this->$parent_category = $new_parent;
	$this->$name = $new_name;
}
}

$temp_product = new Product("asd", "asd");

chubbs

    You mean $this->parent_category and $this->name

    $this->$name would use the value of $name to decide which property of $this to look up.

      4 years later

      try

      class Product
      {
          var $parent_category;
          var $name;
      
      function Product($new_name, $new_parent)
      {
          $this->parent_category = $new_parent;
          $this->name = $new_name;
      }
      }
      
      $temp_product = new Product("asd", "asd"); 
      
        Write a Reply...