src/Container.php
protected function createObject(string $typeName, ?bool $nullable = false, ?bool $checkCycles = true, ?bool $treatAsNotFound = true): ?object
    {
        if ($checkCycles) {
            $this->underConstruction[$typeName] = true;
        }
        
        try {
            if (!isset($this->typeCache[$typeName])) {
                if (\class_exists($typeName) || \interface_exists($typeName, false)) {
                    $this->typeCache[$typeName] = new \ReflectionClass($typeName);
                } else {
                    $this->typeCache[$typeName] = false;
                }
            }
            
            if ($this->typeCache[$typeName] === false) {
                if ($nullable) {
                    return null;
                }
                
                if ($treatAsNotFound) {
                    throw new NotFoundException(\sprintf('Cannot load type: %s', $typeName));
                }
                
                throw new ContainerException(\sprintf('Cannot load type: %s', $typeName));
            }
            
            if (!$this->typeCache[$typeName]->isInstantiable()) {
                if ($nullable) {
                    return null;
                }
                
                throw new NotFoundException(\sprintf('Type is not instantiable: %s', $typeName));
            }
            
            if (isset($this->constructorCache[$typeName])) {
                $con = $this->constructorCache[$typeName];
            } else {
                $con = $this->constructorCache[$typeName] = $this->typeCache[$typeName]->getConstructor() ?: false;
            }
            
            return ($con === false) ? new $typeName() : new $typeName(...$this->populateArguments($con, null, $typeName));
        } finally {
            if ($checkCycles) {
                unset($this->underConstruction[$typeName]);
            }
        }
    }
protected function createObject(string $typeName, ?bool $nullable = false, ?bool $checkCycles = true, ?bool $treatAsNotFound = true): ?object
    {
        if ($checkCycles) {
            $this->underConstruction[$typeName] = true;
        }
        
        try {
            if (!isset($this->typeCache[$typeName])) {
                if (\class_exists($typeName) || \interface_exists($typeName, false)) {
                    $this->typeCache[$typeName] = new \ReflectionClass($typeName);
                } else {
                    $this->typeCache[$typeName] = false;
                }
            }
            
            if ($this->typeCache[$typeName] === false) {
                if ($nullable) {
                    return null;
                }
                
                if ($treatAsNotFound) {
                    throw new NotFoundException(\sprintf('Cannot load type: %s', $typeName));
                }
                
                throw new ContainerException(\sprintf('Cannot load type: %s', $typeName));
            }
            
            if (!$this->typeCache[$typeName]->isInstantiable()) {
                if ($nullable) {
                    return null;
                }
                
                throw new NotFoundException(\sprintf('Type is not instantiable: %s', $typeName));
            }
            
            if (isset($this->constructorCache[$typeName])) {
                $con = $this->constructorCache[$typeName];
            } else {
                $con = $this->constructorCache[$typeName] = $this->typeCache[$typeName]->getConstructor() ?: false;
            }
            
            return ($con === false) ? new $typeName() : new $typeName(...$this->populateArguments($con, null, $typeName));
        } finally {
            if ($checkCycles) {
                unset($this->underConstruction[$typeName]);
            }
        }
    }
Create a new object instance using the public constructor.

@param string $typeName Fully-qualified name of a class.
@param bool $nullable Allow returning null in case of a missing class?
@param bool $checkCycles Check for constructor dependency cycles?
@param bool $treatAsNotFound Treat a missing type as not found error.
@return object