title: pass variable by reference within class? in php
body: <p>I'm working on a hex color class where you can change the color values of any hex code color. In my example, I haven't finished the hex math, but it's not completely relevant to what I'm explaining here. </p>
  
  <p>Naively, I wanted to start to do something that I don't think can be done. I wanted to pass object properties in a method call. <strong>Is this possible?</strong></p>
  
  <pre><code>class rgb {
  
          private $r;
          private $b;
          private $g;
  
          public function __construct( $hexRgb ) {
                  $this-&gt;r = substr($hexRgb, 0, 2 );
                  $this-&gt;g = substr($hexRgb, 2, 2 );
                  $this-&gt;b = substr($hexRgb, 4, 2 );
          }
  
          private function add( &amp; $color, $amount ) {
              $color += amount; // $color should be a class property, $this-&gt;r, etc. 
          }
  
          public function addRed( $amount ) {
                  self::add( $this-&gt;r, $amount );
          }
  
          public function addGreen( $amount ) {
                  self::add( $this-&gt;g, $amount );
          }
  
          public function addBlue( $amount ) {
                  self::add( $this-&gt;b, $amount );
          }
  }
  </code></pre>
  
  <p>If this is not possible in PHP, what is this called and in what languages is it possible?</p>
  
  <p>I know I could do something like</p>
  
  <pre><code>public function add( $var, $amount ) {
      if ( $var == "r" ) {
           $this-&gt;r += $amount
      } else if ( $var == "g" ) {
          $this-&gt;g += $amount
      } ...
  }
  </code></pre>
  
  <p>But I want to do it this cool way. </p>