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

vincej's avatar
Level 15

Error: Typed Property Must Not be Accessed Before Initialisation

Ok, so I have dug around LC and SO and have learned that I need to initialise the declared values before their use. This is odd, as I am getting this only on my development system and not on the production system running on DO.

any way, no matter - ok, so I think, I followed the pattern seen elsewhere on LC. Indeed, the initialisation error has disappeared. But now I have a different error, which I am sure stems from the original error. The console show me that the data is empty however I do have a 200 status. Note: the $request data is coming off of Vue 2.6 and indeed is being passed as I can see in Vue tools. So - bottom line, I suspect that I should not be initialising it against new child. Any suggestions on how I can get this right? Many thanks !

Laravel Controller:

  public function upDateChild(Request $request)
    {
        $request->child_id = new child;				// Added this
        $request->status = new child;                 // Added this

        DB::table('child')
            ->where('child_id', $request->child_id)
            ->update(['status' => $request->status]);
					BLAH BLAH BLAH
}

Console

{data: '', status: 200, statusText: 'OK', headers: {…}, config: {…}, …}config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …}data: ""headers: {cache-control: 'no-cache, private', connection: 'keep-alive', content-encoding: 'gzip', content-type: 'text/html; charset=UTF-8', date: 'Sun, 24 Jul 2022 01:11:15 GMT', …}request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}status: 200statusText: "OK"[[Prototype]]: Object

0 likes
13 replies
RayC's avatar

How are you sending the data? Have you tried dumping the $request to see if the values are being sent as expected?

ddd($request);

This is creating a new instance of 'child', which will have nothing in it yet:

$request->child_id = new child;
$request->status = new child; 

Possibly access the request data like so:

$request->input('child_id');
$request->input('status');
vincej's avatar
Level 15

@RayC Thanks for that. dd($request) does not work on XHR data. Although I did give it a try.

$request->input('child_id');
$request->input('status');

gave me an error 500.

Cheers,

Snapey's avatar

@vincej You should buy Spatie Ray. It will dump to the ray application irrespective of where the dump occurs.

Sinnbeck's avatar

@vincej hi Vince. Good to see you. What error are you getting from

$request->input('child_id');
$request->input('status');

These two alone shouldn't give any errors

vincej's avatar
Level 15

@Sinnbeck Hi Rene! Ok, I will elaborate a little over the answer I gave @rayc .

when I apply this code below I get two different but related errors. Take note of Line 58 marked:

the Console Error

500 internal server error.

Chrome dev tools / XHR / Preview

exception: "Error" file: "/Users/vincejacobs/Sites/KidsClub/app/Http/Controllers/Children.php" line: 58 message: "Typed property Illuminate\Http\Request::$child_id must not be accessed before initialization"

public function upDateChild(Request $request)
    {
        $request->input('child_id');       		// Line 58
        $request->input('status');

        DB::table('child')
            ->where('child_id', $request->child_id)
            ->update(['status' => $request->status]); 
}
vincej's avatar
Level 15

It does not make any sense to me either. I only stuck it in there following some other LC posts dealing with the same error. Putting aside the obvious problem being discussed, the mystery is that my dev machine is a mirror image of my production machine. Everything works fine on production.

My Production code

public function upDateChild(Request $request)
    {
        DB::table('child')
            ->where('child_id', $request->child_id)
            ->update(['status' => $request->status]);

        $now = Carbon::now()->format('Y-m-d');

        $count = DB::table('attendance')
            ->select('date')
            ->where('date', '=', $now)
            ->count();

        if ($count > 0) {
            DB::table('attendance')
                ->insert(['child_id' => $request->child_id, 'timeIn' => 'absent', 'date' => $now, 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
        }
    }
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@vincej can you try deleting your vendor folder and run composer install?

vincej's avatar
Level 15

@Sinnbeck YAHHHOOOO! FIXED !!! You are a RockStar!!

who would think the vendor file got screwed up?

Many thanks !!

Sinnbeck's avatar

@vincej not quite sure sadly. But I had a feeling it was somehow changed. Perhaps your IDE changed the file by accident :)

Please or to participate in this conversation.