original_string: public function tempnam($dir, $prefix)
      {
          list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
  
          // If no scheme or scheme is "file" or "gs" (Google Cloud) create temp file in local filesystem
          if (null === $scheme || 'file' === $scheme || 'gs' === $scheme) {
              $tmpFile = @tempnam($hierarchy, $prefix);
  
              // If tempnam failed or no scheme return the filename otherwise prepend the scheme
              if (false !== $tmpFile) {
                  if (null !== $scheme && 'gs' !== $scheme) {
                      return $scheme.'://'.$tmpFile;
                  }
  
                  return $tmpFile;
              }
  
              throw new IOException('A temporary file could not be created.');
          }
  
          // Loop until we create a valid temp file or have reached 10 attempts
          for ($i = 0; $i < 10; ++$i) {
              // Create a unique filename
              $tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
  
              // Use fopen instead of file_exists as some streams do not support stat
              // Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
              $handle = @fopen($tmpFile, 'x+');
  
              // If unsuccessful restart the loop
              if (false === $handle) {
                  continue;
              }
  
              // Close the file if it was successfully opened
              @fclose($handle);
  
              return $tmpFile;
          }
  
          throw new IOException('A temporary file could not be created.');
      }
code: public function tempnam($dir, $prefix)
      {
          list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
  
          // If no scheme or scheme is "file" or "gs" (Google Cloud) create temp file in local filesystem
          if (null === $scheme || 'file' === $scheme || 'gs' === $scheme) {
              $tmpFile = @tempnam($hierarchy, $prefix);
  
              // If tempnam failed or no scheme return the filename otherwise prepend the scheme
              if (false !== $tmpFile) {
                  if (null !== $scheme && 'gs' !== $scheme) {
                      return $scheme.'://'.$tmpFile;
                  }
  
                  return $tmpFile;
              }
  
              throw new IOException('A temporary file could not be created.');
          }
  
          // Loop until we create a valid temp file or have reached 10 attempts
          for ($i = 0; $i < 10; ++$i) {
              // Create a unique filename
              $tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
  
              // Use fopen instead of file_exists as some streams do not support stat
              // Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability
              $handle = @fopen($tmpFile, 'x+');
  
              // If unsuccessful restart the loop
              if (false === $handle) {
                  continue;
              }
  
              // Close the file if it was successfully opened
              @fclose($handle);
  
              return $tmpFile;
          }
  
          throw new IOException('A temporary file could not be created.');
      }
code_tokens: public function tempnam ( $ dir , $ prefix ) { list ( $ scheme , $ hierarchy ) = $ this -> getSchemeAndHierarchy ( $ dir ) ; // If no scheme or scheme is "file" or "gs" (Google Cloud) create temp file in local filesystem if ( null === $ scheme || 'file' === $ scheme || 'gs' === $ scheme ) { $ tmpFile = @ tempnam ( $ hierarchy , $ prefix ) ; // If tempnam failed or no scheme return the filename otherwise prepend the scheme if ( false !== $ tmpFile ) { if ( null !== $ scheme && 'gs' !== $ scheme ) { return $ scheme . '://' . $ tmpFile ; } return $ tmpFile ; } throw new IOException ( 'A temporary file could not be created.' ) ; } // Loop until we create a valid temp file or have reached 10 attempts for ( $ i = 0 ; $ i < 10 ; ++ $ i ) { // Create a unique filename $ tmpFile = $ dir . '/' . $ prefix . uniqid ( mt_rand ( ) , true ) ; // Use fopen instead of file_exists as some streams do not support stat // Use mode 'x+' to atomically check existence and create to avoid a TOCTOU vulnerability $ handle = @ fopen ( $ tmpFile , 'x+' ) ; // If unsuccessful restart the loop if ( false === $ handle ) { continue ; } // Close the file if it was successfully opened @ fclose ( $ handle ) ; return $ tmpFile ; } throw new IOException ( 'A temporary file could not be created.' ) ; }
docstring: Creates a temporary file with support for custom stream wrappers.
  
  @param string $dir    The directory where the temporary filename will be created
  @param string $prefix The prefix of the generated temporary filename
  Note: Windows uses only the first three characters of prefix
  
  @return string The new temporary filename (with path), or throw an exception on failure
docstring_tokens: Creates a temporary file with support for custom stream wrappers .