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

PhoeniX5's avatar

Namespace declaration statement has to be the very first statement or after any declare call in the script

I need to host my Laravel app in internet when running it in local server it works without issues but in the internet server it keeps saying :

Namespace declaration statement has to be the very first statement or after any declare call in the script

This is my namespace :

<?php
namespace App\Http\Controllers;

0 likes
7 replies
manelgavalda's avatar

Maybe you have some spaces or intros before the <?php tag. Make sure that the tag is the first thing on top of the class. If this is fine, can you post the rest of the code?

PhoeniX5's avatar

@MANELGAVALDA - <?php is the first thing in the page, here is a part of code from beginning :

<?php
namespace App\Http\Controllers;

use Validator;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use App\Demo;
use DB;
use Auth;
use Yajra\DataTables\DataTables;

class DemoController extends Controller
{
    public $code;
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('demo.support');
    }
...
STEREOH's avatar

Check that your IDE is encoding your file in UTF-8 without BOM.

munazzil's avatar

Have you correctly closed the closing tags?

<?php
 namespace App\Http\Controllers;

 use Validator;
 use Illuminate\Http\Request;
 use Illuminate\Support\Str;
 use App\Demo;
 use DB;
 use Auth;
 use Yajra\DataTables\DataTables;

 class DemoController extends Controller
  {
public $code;
/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    return view('demo.support');
}
 }
munazzil's avatar

Else check there is space after <?php. check the spaces.

STEREOH's avatar
STEREOH
Best Answer
Level 18
  1. You're missing a whitespace somewhere
  2. Your file is encoded in UTF8 WITH BOM
  3. The problem is not in this file

There's really nothing else.

Please or to participate in this conversation.