title: PHP run function/logic when object property set
body: <p>Every time I set a PHP object property, I want another property of the same object to be 20% of this value, or alternately put; I want to calculate the VAT at 20% of another property when I set the NetValue.</p>
  
  <p>In C# it would be something like:</p>
  
  <pre><code>public class Product
  {
      public decimal VAT { get; set; }
      private decimal _NetValue;
      public decimal NetValue { get { return _NetValue; } set { _NetValue = value; this.VAT = (value * 0.2M); } }
  }
  </code></pre>
  
  <p>So back in PHP, when I do:</p>
  
  <pre><code>$product = new Product();
  $product-&gt;NetValue = 10;
  echo $product-&gt;VAT;
  </code></pre>
  
  <p>It should output: <code>2</code>.</p>
  
  <p>How can I achieve this, since you can only set constants as object properties in PHP.  Is it possible?  I can't see how putting anything in the constructor can achieve this as mentioned in similar questions.</p>