My practical question here is: what should I learn exactly?
My plan would be to focus on backend programming and learn Laravel anyway, but what knowledge of php do I need to have first to move on to Laravel? Is it enough if I just know the very basics like variables, functions, sessions, globals etc. or should my knowledge be much deeper?
Is it similar with php and Laravel?
Thanks in advance.
What to learn comes from why you want to learn PHP. Look at the jobs you want. What do they use?
I want to learn php because I want to learn Laravel.
…And why do you want to learn Laravel? The context and use cases highlight what parts of the language are most important.
Likely familiarizing yourself with the basic control structures before focusing on what you actually want to learn will be adequate.
Just for fun?
My point here is that languages are just tools. We learn them for specific tasks or jobs. The task or job will naturally determine what parts of the language you need.
I would preferrably use it as a backend api in combination with for example a react or vue frontend.
You are missing my point. Why Laravel and not a different tool?
I’m not missing your point, I’m trying to get an answer to my actual question instead of starting a discussion on why to use Laravel.
Learning a language or framework ‘just because’ is fine, but if you don’t have a specific motivation or goal for why Larvel over other options, we can’t provide that for you. The best we can offer is ‘learn the basics’.
For example, I learned Rust because I wanted to see why the memory safety and ergonomics it offered was better than my options in C. That focused my efforts on specific parts of the language. The specific project I wanted to work on further focused my efforts onto specific parts of the language.
You can learn Laravel before you learn PHP without much issues but a few weird gotchas you’ll hit and you’ll want to learn these:
- How to use Docker. PHP is a bit of a PITA to set up locally and has some pain points that don’t exist in node. It’s more than just managing PHP versions, the language itself can be configured too and a lot of features come from extensions written in C. Learning Docker eliminates a lot of the headaches when switching around PHP projects.
- Object accessors are done like
- Variables are defined with
$ as the first character but if you do something like
$$var that’s actually called a “Variable Variable”… go look them up in the docs
- Accessing properties or methods statically is done like this:
MyClass::staticProperty which is weird if you’re coming from JS
- It’s not a strongly typed language and it is interpreted like JS however PHP has “type hints” built into the language. Learn about those.
- PHP is Object Oriented… sort of but to get imports to work the way you might be used to in other OO languages you need a tool called
composer and use something called
PSR-4 Autoloading. You’ll want to go look up what PSR in PHP is and get familiar with their standards. Also the autoloading bit, Laravel handles for you out of the box. But you’ll want to know what it is and understand the different ways PHP can be used with autoloading (classmap is another common autoloading standard)
- You have interfaces now! Learn how to use them.
- Magic methods. PHP has a concept called “magic methods”. They’re super powerful and Laravel leveredges them under the hood extensively. It’s actually the most divisive practice and when you hear people complain about Laravel it’s often that they disagree with the “magic”. What they’re referring to is the heavy usage of PHP magic methods which can make code discovery and navigation difficult.
- String concatenation is done like
Highly recommend using laracasts.com they’re not 100% free but there’s lots of free courses like these:
Laravel Stuff to Learn
- Start with Laracasts and follow along the free material there
- After you’re comfortable with the basics of Laravel the next most important thing to learn is the IoC container and make sure you understand Dependency Injection.
- Laravel also utilizes a few design patterns in the framework so understanding the patterns may help you understand the framework better
- ORM which you may already be familiar with is a pattern for talking to databases without writing raw queries
- The ORM that Laravel uses is called Eloquent and it is an implementation of the “Active Record” pattern
- The architecture of the framework is MVC (model, view, controller)
- Eloquent also provides access to what’s called a Query Builder and follows the very popular Builder pattern
- Most core services and tools in the framework are available as a Facade which is a controversial pattern sometimes called an anti-pattern but learn about it and you’ll Laravel addresses most of the concerns by making them easy to test
Hopefully that gives you a good start. Good luck!
As someone who uses PHP professionally (and has used Laravel in a previous job), it’s not something I’d recommend for casual learning. PHP isn’t a very intuitive language necessarily, and Laravel is a complicated framework. And even though it is the most prolific PHP framework, it’s not really that prevalent in the industry either, compared to other languages/frameworks like Rails especially.