Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lemmel's avatar

a precise string in a blade make laravel rendering of a page failing

Well to be honest, being an experienced developper I don't think it possible (it would have been different if another language than PHP was involved), but being a beginner with laravel (but not with PHP) I'm at my wits end.

So after an installation of Laravel 5.4, and added several routes and blades, migrated, customized the App\Exceptions\Handler class (in order to send an mail at each exception), I stumbled on this peculiar thing: whenever I use a certain string in a blade I get exceptions in the logs. The moment I remove the string, the problem disappear.

Here is the string:

    <script src="js/hghhgueryjs">

Please note that spaces are significant, the gibberish hghhg is not but something has to be there.

There can be either a lot of text of only this line it will failed, but if this line is not there all is good.

I really can't make any sens out of this, and as a beginner I can't think of another action except read the source of laravel but it would be a overwhelming task.

I didn't take the time to test on a fresh installation (as I generally do), because it would imply a bug in Laravel. Clearly I did something I shouldn't.

Has someone an idea ?

P.S. :

  • Laravel 5.4
  • php-fpm 7.0
  • nginx 1.10.3
  • debian current stable
  • MariaDB 10.1.23
  • php modules: bcmath, cache, cli, common, curl, fpm, fxsl, gd, http, igbinary, intl, json, mbstring, mcrypt, memcached, msgpack, net, pear, soap, xml, yac, yaml, zip, mysql
  • env file : APP_ENV=local APP_DEBUG=true APP_LOG_LEVEL=debug
  • composer.json: "require": { "php": ">=5.6.4", "laravel/framework": "5.4.", "laravel/tinker": "~1.0" }, "require-dev": { "fzaninotto/faker": "~1.4", "mockery/mockery": "0.9.", "phpunit/phpunit": "~5.7" }, "autoload": { "classmap": [ "database" ], "psr-4": { "App\": "app/" } }

Here are the exceptions I receive as a mail (3 separate mails):

(1/1) FatalThrowableError
Call to a member function send() on array
in index.php (line 56)
(1/1) FatalErrorException
Uncaught Error: Call to a member function send() on array in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
thrown
in HandleExceptions.php (line 112)
(1/1) NotFoundHttpException
in RouteCollection.php (line 179)

with a stack provided

I get the following in the laravel.log

[2017-07-29 20:45:37] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function send() on array in /var/www/html/laravel/blog/public/index.php:56
Stack trace:
#0 {main}  
[2017-07-29 20:45:37] local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Uncaught Error: Call to a member function send() on array in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
  thrown in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 {main}
0 likes
14 replies
Cronix's avatar

Try deleting that entire line and retyping it manually from scratch (no copy/paste). You might have some invisible character there. I don't see why it would cause an error with php by having a script tag in blade, and your errors aren't showing the actual cause. That error is coming from whatever you

customized the App\Exceptions\Handler class (in order to send an mail at each exception)

since it's complaining about the ->send() method (where you're sending the email presumably). I'd put the error handler back to stock so you can see the actual error that's triggering the ->send() error.

Cronix's avatar

Then, apparently you have an additional error going on in your App\Exceptions\Handler dealing with sending the email, preventing you from sending the actual error.

1 like
Snapey's avatar

looks like your script tag tries to load a missing file. this will wind up being passed to your Laravel framework which will throw a 404 not found error.

The other two errors are because your exception handling is not working properly

lemmel's avatar

I did as you advised and removed my customized code from the Exception Handler, and I could read this in the laravel.log:

[2017-07-29 22:20:33] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function send() on null in /var/www/html/laravel/blog/public/index.php:56
Stack trace:
#0 {main}  
[2017-07-29 22:20:33] local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Uncaught Error: Call to a member function send() on null in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
  thrown in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 {main}

The blade is located (ressources/views/login.blade.php) and is loaded in a regular way:

return view('login');

Less logs, but not more useful.

As for your question about fishy characters, and I already checked the file with an hex editor ( I'm originally a C/C++ developper and it is quite a reflex to us ;-) )

P.S.:

  • the blade contains only the fishy line described in the first post
  • there is no middleware
  • I will not be able to answer today as I'm going to the bed, and will be available only in the afternoon
  • I got in my laravel.log file the following logs but I'm unable to reproduce the error; I mention it as it contains an explicit reference to the doomed string (look at the end):
 2017/07/29 18:06:25 [error] 369#369: *1 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to a member function send() on null in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
  thrown in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 112
PHP message: PHP Fatal error:  Uncaught Error: Call to a member function send() on null in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalErrorException))
#1 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(123): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalErrorException))
#2 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#3 {main}
  thrown in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 112" while reading response header from upstream, client: 192.168.1.17, server: _, request: "GET /js/hghhgueryjs HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "192.168.1.12", referrer: "http://192.168.1.12/login"
lemmel's avatar

@Snapey I don't understand: laravel interpret my html code and found that the file doesn't exist ? Why and how would laravel interprets my html code ?

Furthermore initially the file existed, it is just series of test that did produce such a line :-). For the sake of the bug hunting I changed the code so the referenced file exists and the exception still get triggered :-(

Here is the login.blade.php:

    <script src="js/hghhguery.js">

now the file hghhguery.js exists and is readable.

Here is the function called in the controller:

  public function login(Request $request)
  {
    return view('login');
  }

Here is the laravel.log:

[2017-07-30 07:00:15] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function send() on null in /var/www/html/laravel/blog/public/index.php:56
Stack trace:
#0 {main}  
[2017-07-30 07:00:15] local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Uncaught Error: Call to a member function send() on null in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
  thrown in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 {main}  

Snapey's avatar

I don't understand: laravel interpret my html code and found that the file doesn't exist ? Why and how would laravel interprets my html code ?

because your .htaccess file says any request coming to the web server that cannot be found should be redirected to index.php (the bootstrap for laravel)

1 like
Snapey's avatar

you still have an error in the exception handler

lemmel's avatar

@Snapey about the .htaccess; I didn't think about this; so it means that any ressouces file not found will generate an error in laravel.

@Snapey about an error in the exception handler; not sure or not found: I reverted the file into its "original state":

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Support\Facades\Mail;
use App\Mail\ErrorOccured;

class Handler extends ExceptionHandler
{
    protected $dontReport = [
        \Illuminate\Auth\AuthenticationException::class,
        \Illuminate\Auth\Access\AuthorizationException::class,
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
        \Illuminate\Session\TokenMismatchException::class,
        \Illuminate\Validation\ValidationException::class,
    ]; 
    public function report(Exception $exception)
    {
      parent::report($exception);
    }
    public function render($request, Exception $exception)
    {
      parent::render($request, $exception);
    }
    protected function unauthenticated($request, AuthenticationException $exception)
    {   
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }

        return redirect()->guest(route('login'));
    }

And keep in mind that if there is something else in my blade there is no error message. As a reminder, here is the laravel.log:

[2017-07-30 10:03:53] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function send() on null in /var/www/html/laravel/blog/public/index.php:56
Stack trace:
#0 {main}  
[2017-07-30 10:03:53] local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Uncaught Error: Call to a member function send() on null in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(89): Illuminate\Foundation\Bootstrap\HandleExceptions->renderHttpResponse(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\Debug\Exception\FatalThrowableError))
#2 {main}
  thrown in /var/www/html/laravel/blog/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:112
Stack trace:
#0 {main}  


Snapey's avatar

about the .htaccess; I didn't think about this; so it means that any ressouces file not found will generate an error in laravel.

Well it will throw fileNotFound exception, but you can always filter that out from your own exception handling.

Exception handling still broke for some reason though...

1 like
Snapey's avatar

The error is saying that $response is null

$response->send();

in index.php

This is main call to the framework but for some reason nothing is being returned.

1 like
jlrdw's avatar
jlrdw
Best Answer
Level 75

@lemmel are you clearing all cache, browser and any laravel while trouble shooting? I have in pass actually fixed an error, but due to cache did not realize it right away.

1 like
lemmel's avatar

@jlrdw clearing all the caches of the browser did removed the error. But it is a bit fustrating:

  • I will never know why there was an error, or even if there was an error
  • I must confess that I'm a bit afraid of Laravel's behaviour: I don't understand why the cache produced such a behaviour, and I think that it should not have have such a behaviour

Thanks @Snapey as your post gave me some insight of Laravel's behaviour.

At last, if someone has an idea about the reason why Laravel's cache can produce such a behaviour, then don't hesitate and enlighten me: this can only calm down my fears about Laravel.

Thanks to all of you !

P.S.:

  • at least it is a big lesson to me: I must ask my users to clear their browser cache
  • I will mark the discussion are "resolved" after waiting some time in the hope that someone can shed some light on this.
jlrdw's avatar

At last, if someone has an idea about the reason why Laravel's cache can produce such a behaviour, then don't hesitate and enlighten me: this can only calm down my fears about Laravel.

Blade and cached views, I don't use blade, I use normal html mixed with php. And I sanitize all input like

public static function fixValue($rvalue) {
    $rvalue = empty($rvalue) && !is_numeric($rvalue) ? NULL :    trim(strip_tags($rvalue));
        return $rvalue;
    }

And I can echo content similar to cakephp, just dig into that api doc.

Edit: Not saying blade is bad, just saying I don't use it.

lemmel's avatar

Thanks for the comment.

I will stick to Laravel tools as I want to be fast and seize the opportunity learn something new.

Thanks for sharing :-)

Please or to participate in this conversation.