Trying to access array offset on value of type null (Schema.PhP)

Out of the blue, the queue::work cron job started spamming me with:
PHP Notice: Trying to access array offset on value of type null in /home/user/domains/ on line 45 PHP Fatal error: Uncaught Error: Call to a member function connection() on null in /home/user/domains/

I found the problem in the bootstrap/cache folder, where the config file was cleared (0 bytes, empty, zilch).
After renaming the cache folder and creating a new one (probably unnecessary?), a new config file was created automatically and all is well.

Still left with the question: What is overwriting the config file and why is it doing so with emptiness?

Also, aren’t the files in the cache supposed to have 755 permission? Config and routes-v7 are set to 644 and I cannot change it (well, I can but it’s quickly undone).

@david can you please help?


Have you updated recently or changed PHP versions?

Nope. None of that. The empty config file had a time stamp of exactly 23:00, which makes it not only very suspect to being a triggered event, but also a pinpointed one. No other files were modified on or around that time.

David, how about that other part of my question. It seems to me that at least routes-7.php requires execution permission.

That also explains these errors that I’m getting:

In RouteServiceProvider.php line 108:

che/routes-v7.php): failed to open stream: No such file or directory

Through deduction I came to the conclusion that the artisan optimize is responsible for setting the permissions on routes-7 back to 644.
I thought it was a good idea to run this every 10 minutes (no harm, no foul), but even if I run this only when required, it still should leave the permissions well enough alone, no?


No, routes-v7.php does not need execute perm. The purpose of artisan optimize is to regenerate bootstrap/cache/{config,routes-v7}.php. Depending on how you call it, it will reset permissions and ownership of these files. If the shell you are calling artisan optimize from has a umask 77, those regenerated files will have a perm 0600, if your shell has a umask 22, your files will have a perm 0644. If you are calling artisan optimize as user root, your regenerated files will have owner root.

Can you do

ls -la bootstrap/cache

for us?

I’m on shared hosting, but it looks like this:

Type Name Size Perm. Date UID GID
file config.php 47.3k 644 Feb 28 11:10 2022 myUser myUser
file packages.php 3.31k 755 Feb 24 16:21 2022 myUser myUser
file routes-v7.php 0.554M 755 Feb 28 11:10 2022 myUser myUser
file services.php 16.8k 755 Feb 24 16:21 2022 myUser myUser

(routes is manually set to 755, which does seem to get rid of the error in the RouteServiceProvider)