Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Variable Types and Return Types

Premium
4 min read

Have you noticed that Laravel 10 came with a big skeleton rewriting to use PHP types everywhere - for parameters, properties, variables, and method returns. But let's explore what are the possible types and their syntax details.

Let's look at two code samples:

Without types:

class UserService {
 
public $data;
 
public function processData($user)
{
// ...
}
}

With types:

use App\Models\User;
 
class UserService {
 
public array $data;
 
public function processData(User $user): User
{
// ...
}
}

The second example is more readable, right? If a developer opens the first example for the first time, he would have...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…