3-in-1 PHP Tip: Array Diff, Exception, Method Params

preview_player
Показать описание
A practical example from Laravel Pulse source code. In my opinion, it's one of the best ways to learn: looking at someone's code and trying to debug it step-by-step for a better understanding.

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

That's really neat! I like how you're digging into open source projects for inspiration

Jelle-DV
Автор

These days you are talking about awesome topics.. ❤

shubhamsahuSD
Автор

My first impression about inline assignment of the parameter is "Oh no, that will be hard to spot when debugging. Put it on a separate line." But I am not a genius, maybe it is really cool.

roman_zabigaliuk
Автор

Yeah php built-in array functions are of great use including array_diff but what i didn't like and didn't recommend is the inline declaration of variable allowed which is also reported by php mess detector rules not to allow inline declarations in ifs or loops.

shahsawoodshinwari
Автор

A separate variable is clearer. Programming is not just about reducing lines just for the sake of reducing a line.

genechristiansomoza
Автор

Insert or update or delete based on records selected, I user selected new records and deleted some I use array_diff

blpraveen
Автор

Hello Sir, can you help me with this?

I have installed spatie/laravel-backup composer package on my Laravel app. This backup command is working fine in the vs code terminal but when I try to run this command from the controller then it's not working. Basically I want to take backup of postgres database. If there is any other solution for this please let me know.

ladlanomi
Автор

It`s looks like C style coding.
But in some cases can be useful in PHP also.

andreyshevtsiv
Автор

Instantiating variables in your method calls or if statements is generally to be avoided! It's quite a code smell and I'd strongly recommend against this style
In this case, rather use typed parameters if you want to show readability.

Doing it this way puts that object into memory for a much larger scope than you need, bad for memory and debugging that is a nightmare

JohnRoux
Автор

I mean, I do it from time to time. But this example is a bit dense, too much on one line. It should just have been a backed enum

spicynoodle
Автор

if ( ! $user = User::find($id))

Why laravel dont allow this?

amitsolanki