Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: userc865b
Added: Jun 11, 2018 2:41 PM
Views: 12
Tags: php
how to handle Multiple constructors
  1. class Test{
  2.  
  3.  
  4.     public function __construct($p1, $p2=null, $p3=null) {
  5.  
  6.  
  7.  
  8.         $argumentsPassed=func_num_args();
  9.         echo $argumentsPassed;
  10.         if ($argumentsPassed==3)
  11.             $this->test3();
  12.         elseif ($argumentsPassed==1)
  13.             $this->test1();
  14.     }
  15.  
  16.     private function test3()
  17.     {
  18.         echo "test3";
  19.     }
  20.  
  21.     private function test1()
  22.     {
  23.         echo "test1";
  24.     }
  25. }
  26.  
  27. $test=10;$et=88;$t="was geht";
  28. $test= new Test($test);