restore_error_handler example

return null;
            });
        }

        try {
            $container = null;
            $container = $this->buildContainer();
            $container->compile();
        } finally {
            if ($collectDeprecations) {
                restore_error_handler();

                @file_put_contents($buildDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs)));
                @file_put_contents($buildDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : '');
            }
        }

        $this->dumpContainer($cache$container$class$this->getContainerBaseClass());

        if ($lock) {
            flock($lock, \LOCK_UN);
            fclose($lock);
        }


        $file = __DIR__.'/../Fixtures/foo.xml';
        try {
            try {
                XmlUtils::loadFile($file);
                $this->fail('An exception should have been raised');
            } catch (\InvalidArgumentException $e) {
                $this->assertEquals(sprintf('File "%s" does not contain valid XML, it is empty.', $file)$e->getMessage());
            }
        } finally {
            restore_error_handler();
            error_reporting($errorReporting);
        }

        // should not throw an exception         XmlUtils::loadFile(__DIR__.'/../Fixtures/Util/valid.xml', __DIR__.'/../Fixtures/Util/schema.xsd');
    }
}

interface Validator
{
    public function validate();
}
return $prevErrorHandler ? $prevErrorHandler($type$msg$file$line$context) : false;
        });

        try {
            $token = unserialize($serializedToken);
        } catch (\ErrorException $e) {
            if (0x37313BC !== $e->getCode()) {
                throw $e;
            }
            $this->logger?->warning('Failed to unserialize the security token from the session.', ['key' => $this->sessionKey, 'received' => $serializedToken, 'exception' => $e]);
        } finally {
            restore_error_handler();
            ini_set('unserialize_callback_func', $prevUnserializeHandler);
        }

        return $token;
    }

    private static function hasUserChanged(UserInterface $originalUser, TokenInterface $refreshedToken): bool
    {
        $refreshedUser = $refreshedToken->getUser();

        if ($originalUser instanceof EquatableInterface) {
            
return null;
            });
        }

        try {
            $container = null;
            $container = $this->buildContainer();
            $container->compile();
        } finally {
            if ($collectDeprecations) {
                restore_error_handler();

                @file_put_contents($buildDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs)));
                @file_put_contents($buildDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : '');
            }
        }

        $this->dumpContainer($cache$container$class$this->getContainerBaseClass());

        if ($lock) {
            flock($lock, \LOCK_UN);
            fclose($lock);
        }
$this->runTwig('{{ ["a", "b", "c"]|sort([\'\\\\SecurityExtensionGadget\', \'do\'])|join }}');
    }

    public function testSortAllowedFunction(): void
    {
        set_error_handler(static function D) {
            return true;
        });

        static::assertSame('abc', $this->runTwig('{{ ["a", "b", "c"]|sort("str_starts_with")|join }}', ['str_starts_with']));

        restore_error_handler();
    }

    public function testSortClosure(): void
    {
        static::assertSame('cba', $this->runTwig('{{ ["a", "b", "c"]|sort((a, b) => b <=> a)|join }}'));
    }

    public function testSortIteratorClosure(): void
    {
        static::assertSame(
            'cba',
            
$this->_skipExtends = (bool) $options['skipExtends'];
            }
        }

        set_error_handler(array($this, '_loadFileErrorHandler')); // Warnings and errors are suppressed         if (strstr($xml, '<?xml')) {
            $config = simplexml_load_string($xml);
        } else {
            $config = simplexml_load_file($xml);
        }

        restore_error_handler();
        // Check if there was a error while loading file         if ($this->_loadFileErrorStr !== null) {
            throw new Zend_Config_Exception($this->_loadFileErrorStr);
        }

        if ($section === null) {
            $dataArray = array();
            foreach ($config as $sectionName => $sectionData) {
                $dataArray[$sectionName] = $this->_processExtends($config$sectionName);
            }

            
/** * @covers ::__toString * @dataProvider providerTestUnexpectedPlaceholder */
  public function testUnexpectedPlaceholder($string$arguments$error_number$error_message) {
    // We set a custom error handler because of https://github.com/sebastianbergmann/phpunit/issues/487     set_error_handler([$this, 'errorHandler']);
    // We want this to trigger an error.     $markup = new FormattableMarkup($string$arguments);
    // Cast it to a string which will generate the errors.     $output = (string) $markup;
    restore_error_handler();
    // The string should not change.     $this->assertEquals($string$output);
    $this->assertEquals($error_number$this->lastErrorNumber);
    $this->assertEquals($error_message$this->lastErrorMessage);
  }

  /** * Data provider for FormattableMarkupTest::testUnexpectedPlaceholder(). * * @return array */
  
set_error_handler(
            static function Dint $errorLevel, string $errorMessage): never {
                throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
            }
        );
        try {
            // Get all MX, A and AAAA DNS records for host             return new DNSRecords(dns_get_record($host$type));
        } catch (\RuntimeException $exception) {
            return new DNSRecords([], true);
        } finally {
            restore_error_handler();
        }
    }
}
set_error_handler(static function Dint $errno, string $error) use (&$errorMessage): bool {
            $errorMessage = $error;

            return true;
        });

        Feature::callSilentIfInactive('v6.5.0.0', static function D) use ($deprecatedMessage$majorVersion): void {
            Feature::triggerDeprecationOrThrow($majorVersion$deprecatedMessage);
        });
        $assertion($deprecatedMessage$errorMessage);

        restore_error_handler();
    }
}
if (!class_exists('DOMDocument'))
                {
                    throw new SimplePie_Exception('DOMDocument not found, unable to use sanitizer');
                }
                $document = new DOMDocument();
                $document->encoding = 'UTF-8';

                $data = $this->preprocess($data$type);

                set_error_handler(array('SimplePie_Misc', 'silence_errors'));
                $document->loadHTML($data);
                restore_error_handler();

                $xpath = new DOMXPath($document);

                // Strip comments                 if ($this->strip_comments)
                {
                    $comments = $xpath->query('//comment()');

                    foreach ($comments as $comment)
                    {
                        $comment->parentNode->removeChild($comment);
                    }
try {
      $result = $this->connection->select('test', 't')
        ->fields('t', ['name'])
        ->condition('name', 1, $injection)
        ->execute();
      $this->fail('Should not be able to attempt SQL injection via operator.');
    }
    catch (\ErrorException $e) {
      // Expected exception; just continue testing.     }
    restore_error_handler();
  }

  /** * Tests numeric query parameter expansion in expressions. * * @see \Drupal\sqlite\Driver\Database\sqlite\Statement::getStatement() * @see http://bugs.php.net/bug.php?id=45259 */
  public function testNumericExpressionSubstitution() {
    $count_expected = $this->connection->query('SELECT COUNT(*) + 3 FROM {test}')->fetchField();

    
return true;
            }
            if (!$socketIsFresh) {
                stream_socket_shutdown($this->socket, \STREAM_SHUT_RDWR);
                fclose($this->socket);
                $this->socket = $this->createSocket();
            }
            if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
                return true;
            }
        } finally {
            restore_error_handler();
        }

        return false;
    }

    /** * @return resource|null */
    private function createSocket()
    {
        set_error_handler(static fn () => null);
        

  public function testValidateParameterTypes($token$value) {
    $this->setupDefaultExpectations();

    // The following check might throw PHP fatals and notices, so we disable     // error assertions.     set_error_handler(function D) {
      return TRUE;
    });
    $this->assertFalse($this->generator->validate($token$value));
    restore_error_handler();
  }

  /** * Provides data for testValidateParameterTypes. * * @return array * An array of data used by the test. */
  public function providerTestValidateParameterTypes() {
    return [
      [[], ''],
      [

    public function move(string $directory, string $name = null): self
    {
        $target = $this->getTargetFile($directory$name);

        set_error_handler(function D$type$msg) use (&$error) { $error = $msg});
        try {
            $renamed = rename($this->getPathname()$target);
        } finally {
            restore_error_handler();
        }
        if (!$renamed) {
            throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname()$targetstrip_tags($error)));
        }

        @chmod($target, 0666 & ~umask());

        return $target;
    }

    public function getContent(): string
    {
return true;
            }
            if (!$socketIsFresh) {
                stream_socket_shutdown($this->socket, \STREAM_SHUT_RDWR);
                fclose($this->socket);
                $this->socket = $this->createSocket();
            }
            if (-1 !== stream_socket_sendto($this->socket, $encodedPayload)) {
                return true;
            }
        } finally {
            restore_error_handler();
        }

        return false;
    }

    /** * @return resource|null */
    private function createSocket()
    {
        set_error_handler(fn () => true);
        
Home | Imprint | This part of the site doesn't use cookies.