diff --git a/.htaccess b/.htaccess
index 73ce26b..476f23f 100644
--- a/.htaccess
+++ b/.htaccess
@@ -35,7 +35,7 @@ AddEncoding gzip svgz
 
 # PHP 5, Apache 1 and 2.
 <IfModule mod_php5.c>
-  php_value assert.active                   0
+  php_value assert.active                   1
   php_flag session.auto_start               off
   php_value mbstring.http_input             pass
   php_value mbstring.http_output            pass
diff --git a/core/lib/Drupal/Core/Template/TwigEnvironment.php b/core/lib/Drupal/Core/Template/TwigEnvironment.php
index 346dcc2..3795723 100644
--- a/core/lib/Drupal/Core/Template/TwigEnvironment.php
+++ b/core/lib/Drupal/Core/Template/TwigEnvironment.php
@@ -42,6 +42,8 @@ class TwigEnvironment extends \Twig_Environment {
    *   The options for the Twig environment.
    */
   public function __construct($root, \Twig_LoaderInterface $loader = NULL, $options = array()) {
+    assert('file_exists($root)');
+
     // @todo Pass as arguments from the DIC.
     $this->cache_object = \Drupal::cache();
 
@@ -78,6 +80,9 @@ protected function isFresh($cache_filename, $name) {
    * Compile the source and write the compiled template to disk.
    */
   public function updateCompiledTemplate($cache_filename, $name) {
+    assert('is_string($cache_filename)');
+    assert('is_string($name)');
+
     $source = $this->loader->getSource($name);
     $compiled_source = $this->compileSource($source, $name);
     $this->storage()->save($cache_filename, $compiled_source);
@@ -108,6 +113,9 @@ public function updateCompiledTemplate($cache_filename, $name) {
    *   When an error occurred during compilation.
    */
   public function loadTemplate($name, $index = NULL) {
+    assert('is_string($name)');
+    assert('is_int($index)');
+
     $cls = $this->getTemplateClass($name, $index);
 
     if (isset($this->loadedTemplates[$cls])) {
@@ -140,7 +148,10 @@ public function loadTemplate($name, $index = NULL) {
         $this->initRuntime();
     }
 
-    return $this->loadedTemplates[$cls] = new $cls($this);
+    $this->loadedTemplates[$cls] = new $cls($this);
+
+    assert('$this->loadedTemplates[$cls] instanceof \\Twig_TemplateInterface');
+    return $this->loadedTemplates[$cls];
   }
 
   /**
@@ -152,6 +163,8 @@ protected function storage() {
     if (!isset($this->storage)) {
       $this->storage = PhpStorageFactory::get('twig');
     }
+
+    assert('$this->storage instanceof \\Drupal\\Component\\PhpStorage\\PhpStorageInterface');
     return $this->storage;
   }
 
@@ -167,6 +180,8 @@ protected function storage() {
    *   The template class name.
    */
   public function getTemplateClass($name, $index = NULL) {
+    assert('is_string($name)');
+    assert('is_int($index)');
     // We override this method to add caching because it gets called multiple
     // times when the same template is used more than once. For example, a page
     // rendering 50 nodes without any node template overrides will use the same
@@ -175,6 +190,8 @@ public function getTemplateClass($name, $index = NULL) {
     if (!isset($this->templateClasses[$cache_index])) {
       $this->templateClasses[$cache_index] = $this->templateClassPrefix . hash('sha256', $this->loader->getCacheKey($name)) . (NULL === $index ? '' : '_' . $index);
     }
+
+    assert('is_string($this->templateClasses[$cache_index])');
     return $this->templateClasses[$cache_index];
   }
 
@@ -201,6 +218,7 @@ public function getTemplateClass($name, $index = NULL) {
    * @see \Drupal\Core\Template\Loader\StringLoader::exists()
    */
   public function renderInline($template_string, array $context = array()) {
+    assert('is_string($template_string)');
     // Prefix all inline templates with a special comment.
     $template_string = '{# inline_template_start #}' . $template_string;
     return SafeString::create($this->loadTemplate($template_string, NULL)->render($context));
diff --git a/core/lib/Drupal/Core/Template/TwigExtension.php b/core/lib/Drupal/Core/Template/TwigExtension.php
index 482c888..1be2771 100644
--- a/core/lib/Drupal/Core/Template/TwigExtension.php
+++ b/core/lib/Drupal/Core/Template/TwigExtension.php
@@ -197,6 +197,9 @@ public function getName() {
    *   The generated URL path (relative URL) for the given route.
    */
   public function getPath($name, $parameters = array(), $options = array()) {
+    assert('is_string($name)');
+    assert('$this->urlGenerator instanceof \\Drupal\\Core\\Routing\\UrlGeneratorInterface', 'Twig Extension misconfigured. The most likely culprit is an incorrect module services.yml file.');
+
     $options['absolute'] = FALSE;
     return $this->urlGenerator->generateFromRoute($name, $parameters, $options);
   }
@@ -218,6 +221,9 @@ public function getPath($name, $parameters = array(), $options = array()) {
    * @todo Add an option for scheme-relative URLs.
    */
   public function getUrl($name, $parameters = array(), $options = array()) {
+    assert('is_string($name)');
+    assert('$this->urlGenerator instanceof \\Drupal\\Core\\Routing\\UrlGeneratorInterface', 'Twig Extension misconfigured. The most likely culprit is an incorrect module services.yml file.');
+
     // Generate URL.
     $options['absolute'] = TRUE;
     $generated_url = $this->urlGenerator->generateFromRoute($name, $parameters, $options, TRUE);
@@ -243,6 +249,9 @@ public function getUrl($name, $parameters = array(), $options = array()) {
    * @deprecated in Drupal 8.0.x-dev and will be removed before Drupal 8.0.0.
    */
   public function getUrlFromPath($path, $options = array()) {
+    assert('is_string($path)');
+    assert('$this->urlGenerator instanceof \\Drupal\\Core\\Routing\\UrlGeneratorInterface', 'Twig Extension misconfigured. The most likely culprit is an incorrect module services.yml file.');
+
     // Generate URL.
     $options['absolute'] = TRUE;
     $generated_url = $this->urlGenerator->generateFromPath($path, $options, TRUE);
@@ -267,6 +276,9 @@ public function getUrlFromPath($path, $options = array()) {
    *   A render array representing a link to the given URL.
    */
   public function getLink($text, $url, $attributes = []) {
+    assert('is_string($text)');
+    assert('is_string($url) || $url instanceof \\Drupal\\Core\\Url');
+
     if (!$url instanceof Url) {
       $url = Url::fromUri($url);
     }
@@ -294,6 +306,7 @@ public function getLink($text, $url, $attributes = []) {
    *   The name of the active theme.
    */
   public function getActiveTheme() {
+    assert('$this->themeManager instanceof \\Drupal\\Core\\Theme\\ThemeManagerInterface', 'Twig Extension misconfigured. The most likely culprit is an incorrect module services.yml file.');
     return $this->themeManager->getActiveTheme()->getName();
   }
 
@@ -348,6 +361,8 @@ public function isUrlGenerationSafe(\Twig_Node $args_node) {
    *   An asset library.
    */
   public function attachLibrary($library) {
+    assert('is_string($library)');
+
     // Use Renderer::render() on a temporary render array to get additional
     // bubbleable metadata on the render stack.
     $template_attached = ['#attached' => ['library' => [$library]]];
@@ -365,7 +380,7 @@ public function attachLibrary($library) {
    * @return string|null
    *   The escaped, rendered output, or NULL if there is no valid output.
    */
-  public function escapePlaceholder($env, $string) {
+  public function escapePlaceholder(\Twig_Environment $env, $string) {
     return '<em class="placeholder">' . $this->escapeFilter($env, $string) . '</em>';
   }
 
@@ -390,6 +405,9 @@ public function escapePlaceholder($env, $string) {
    *   The escaped, rendered output, or NULL if there is no valid output.
    */
   public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $charset = NULL, $autoescape = FALSE) {
+    assert('is_string($strategy)');
+    assert('is_string($charset) || is_null($charset)');
+
     // Check for a numeric zero int or float.
     if ($arg === 0 || $arg === 0.0) {
       return 0;
@@ -470,6 +488,8 @@ public function escapeFilter(\Twig_Environment $env, $arg, $strategy = 'html', $
    * @see TwigNodeVisitor
    */
   public function renderVar($arg) {
+    assert('is_string($arg) || is_object($arg) || is_array($arg)');
+
     // Check for a numeric zero int or float.
     if ($arg === 0 || $arg === 0.0) {
       return 0;
diff --git a/core/lib/Drupal/Core/Template/TwigTransTokenParser.php b/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
index c67f463..92c884a 100644
--- a/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
+++ b/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
@@ -61,14 +61,14 @@ public function parse(\Twig_Token $token) {
   /**
    * Detect a 'plural' switch or the end of a 'trans' tag.
    */
-  public function decideForFork($token) {
+  public function decideForFork(\Twig_Token $token) {
     return $token->test(array('plural', 'endtrans'));
   }
 
   /**
    * Detect the end of a 'trans' tag.
    */
-  public function decideForEnd($token) {
+  public function decideForEnd(\Twig_Token $token) {
     return $token->test('endtrans');
   }
 
