original_string: public static function reflectionInstance($classname, $arguments = [], $set_remaining = FALSE, $set_include = FALSE, $set_exclude = FALSE) {
          $reflection = new ReflectionClass($classname);
          if(!$constructor = $reflection->getConstructor()) {
              return new $classname;
          }
  
          $args = self::getReflectionArgs($constructor, $arguments, $missing);
  
          if($missing) {
              $parts = [];
              foreach($missing as $key => $name) {
                  $parts[] = "'$name' (or '$key')";
              }
              $missing = implode(", ", $parts);
              throw new Exception("Can not create object of type '$classname'. Argument $missing needs to be set.");
          }
  
          $instance = $reflection->newInstanceArgs($args);
  
          if($set_remaining) {
              foreach($arguments as $key => $value) {
                  if(is_array($set_include) && !in_array($key, $set_include)) {
                      continue;
                  }
  
                  if(is_array($set_exclude) && in_array($key, $set_exclude)) {
                      continue;
                  }
  
                  $instance->$key = $value;
              }
          }
  
          return $instance;
      }
code: public static function reflectionInstance($classname, $arguments = [], $set_remaining = FALSE, $set_include = FALSE, $set_exclude = FALSE) {
          $reflection = new ReflectionClass($classname);
          if(!$constructor = $reflection->getConstructor()) {
              return new $classname;
          }
  
          $args = self::getReflectionArgs($constructor, $arguments, $missing);
  
          if($missing) {
              $parts = [];
              foreach($missing as $key => $name) {
                  $parts[] = "'$name' (or '$key')";
              }
              $missing = implode(", ", $parts);
              throw new Exception("Can not create object of type '$classname'. Argument $missing needs to be set.");
          }
  
          $instance = $reflection->newInstanceArgs($args);
  
          if($set_remaining) {
              foreach($arguments as $key => $value) {
                  if(is_array($set_include) && !in_array($key, $set_include)) {
                      continue;
                  }
  
                  if(is_array($set_exclude) && in_array($key, $set_exclude)) {
                      continue;
                  }
  
                  $instance->$key = $value;
              }
          }
  
          return $instance;
      }
code_tokens: public static function reflectionInstance ( $ classname , $ arguments = [ ] , $ set_remaining = FALSE , $ set_include = FALSE , $ set_exclude = FALSE ) { $ reflection = new ReflectionClass ( $ classname ) ; if ( ! $ constructor = $ reflection -> getConstructor ( ) ) { return new $ classname ; } $ args = self :: getReflectionArgs ( $ constructor , $ arguments , $ missing ) ; if ( $ missing ) { $ parts = [ ] ; foreach ( $ missing as $ key => $ name ) { $ parts [ ] = "'$name' (or '$key')" ; } $ missing = implode ( ", " , $ parts ) ; throw new Exception ( "Can not create object of type '$classname'. Argument $missing needs to be set." ) ; } $ instance = $ reflection -> newInstanceArgs ( $ args ) ; if ( $ set_remaining ) { foreach ( $ arguments as $ key => $ value ) { if ( is_array ( $ set_include ) && ! in_array ( $ key , $ set_include ) ) { continue ; } if ( is_array ( $ set_exclude ) && in_array ( $ key , $ set_exclude ) ) { continue ; } $ instance -> $ key = $ value ; } } return $ instance ; }
docstring: Invokes constructors by assembling arguments from an array with the help of the reflection API.
  
  The array values will be passed to the constructor based on the argument names of the constructor signature.
  Numeric keys can also be used to specify arguments. A number denotes the n-th argument of the constructor.
  This is especially useful for constructors with a long argument list (where most arguments are defined by default).
  It can be seen as syntethic sugar to the alternative of passing a single option array as an argument.
  
  An exception is thrown if there are missing arguments.
  
  Example:
  
  <code>
  class Test {
  public function __construct($arg1, $arg2 = "Default2", $arg3 = "Default3") {
  $this->arg1 = $arg1;
  $this->arg2 = $arg2;
  $this->arg3 = $arg3;
  }
  }
  </code>
  
  you could instantiate it like this:
  
  <code>
  // as with the new operator
  Misc::reflectionInstance("Test", [ "Value1", "Value2" ]);
  // ->arg1 = "Value1"; ->arg2 = "Value2"; ->arg3 = "Default3";
  
  // by specifying argument names directly
  Misc::reflectionInstance("Test", [ "Value1", "arg3" => "Value3" ]);
  Misc::reflectionInstance("Test", [ "arg1" => "Value1", "arg3" => "Value3" ]);
  // ->arg1 = "Value1"; ->arg2 = "Default2"; ->arg3 = "Default3";
  </code>
  
  @param string $classname The name of the class that should be instantiated
  @param array<mixed> $arguments The arguments that are passed to the constructor
  @param bool $set_remaining If set to TRUE unused parameters will be set as properties of the class after instantiation.
  @param false|array<string> If set to an array, only use keys that are listed in this array
  @param false|array<string> If set to an array, skip keys that are listed in this array
  @return object The created object instance
docstring_tokens: Invokes constructors by assembling arguments from an array with the help of the reflection API .