title: Class template in PHP like in C++
body: <p>Is is possible to create class template in <em>PHP</em> as in <em>C++</em>? <em>PHP</em> probably does not have a similar language structure (like <code>template</code> key words in <em>C++</em>), but maybe there is some clever trick to achieve similar functionality?</p>
  
  <p>I have a <code>Point</code> class that I would like to convert to a template. In class I use typing arguments, therefore, for each class, I would like to pass to the Point method I have to create a new copy of Point class with appropriate types of arguments.</p>
  
  <p>This is sample form <em>C++</em>:</p>
  
  <pre><code>#include&lt;iostream&gt;
  
  template &lt;typename T&gt;
  class Point
  {
      public:
      T x, y;
  
      Point(T argX, T argY)
      {
          x = argX;
          y = argY;
      }
  };
  
  int main() {
      Point&lt;int&gt; objA(1, 2);
      std::cout &lt;&lt; objA.x &lt;&lt; ":" &lt;&lt; objA.y &lt;&lt; std::endl;
  
      Point&lt;unsigned&gt; objB(3, 4);
      std::cout &lt;&lt; objB.x &lt;&lt; ":" &lt;&lt; objB.y &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>And the same in PHP, but it not work at all (of course the last but one line returns an error):</p>
  
  <pre><code>class SomeClass
  {
      public $value;
  
      public function __construct($value = 0)
      {
          $this-&gt;value = $value;
      }
  }
  
  class OtherClass
  {
      public $value;
  
      public function __construct($value = 0)
      {
          $this-&gt;value = $value;
      }
  }
  
  class Point
  {
      public $x;
      public $y;
  
      public function Point(SomeClass $argX, SomeClass $argY)
      {
          $this-&gt;x = $argX;
          $this-&gt;y = $argY;
      }
  }
  
  $objA = new Point(new SomeClass(1), new SomeClass(2));
  echo $objA-&gt;x-&gt;value . ":" . $objA-&gt;y-&gt;value . PHP_EOL;
  
  $objB = new Point(new OtherClass(3), new OtherClass(4));
  echo $objB-&gt;x-&gt;value . ":" . $objB-&gt;y-&gt;value . PHP_EOL;
  </code></pre>