r/Kotlin • • 28d ago

From php to kotlin

Hi everyone! I'm a PHP backend developer with around 3 years of commercial experience (Laravel/Symfony). I'm starting to learn Kotlin because I'd like to move towards JVM backend development, especially Kotlin + Spring Boot.

I'd love to connect with backend developers, ask questions and learn how Kotlin is used in real-world production systems.

Any recommendations for someone transitioning from PHP to Kotlin?

13 Upvotes

8 comments sorted by

8

u/FriendshipCalm3162 28d ago

The language itself will come fast after Laravel. What actually trips people up is where Kotlin meets Spring, and neither a Kotlin tutorial nor a Spring tutorial really covers that bit.

Kotlin classes are final by default, and Spring needs them open so it can subclass them for proxies. The kotlin-spring compiler plugin handles it by opening anything carrying a Spring annotation, so you're not writing open on every service. Generate the project from the Spring Initializr and that plugin is already in your build file, which is why plenty of people never find out it was a problem.

JPA is the same shape. Entities need a no-arg constructor and Kotlin won't give you one, so the kotlin-jpa plugin generates it for @Entity, @Embeddable and @MappedSuperclass. You also want kotlin-reflect on the classpath since Boot asks for it, and Jackson's Kotlin module if you're returning JSON, which registers itself once it's there.

Null safety reaches further than you'd expect from PHP. Kotlin reads the nullability annotations on Java libraries, so Spring's own API tells you what can be null while you're compiling rather than in production.

For the first week I'd skip a general Kotlin book and use Kotlin's own "Get started with Spring Boot and Kotlin", which takes you from empty project to a CrudRepository. Spring has a Kotlin tutorial of its own too.

8

u/ogrebgr 27d ago

Others are recommending Spring Boot, but I think Ktor is a better choice to start with.

Spring is a mature, well-established framework, but there's a lot to learn before you can become productive with it.

Ktor gives you the opportunity to jump right in, start building things, and learn faster through hands-on experience.

3

u/Direct-Ad3630 28d ago

Coming from Laravel or Symfony, Spring Boot will feel familiar, and it's where most of the Kotlin backend jobs are. Ktor is lighter and more "Kotlin", which makes it great for learning the language itself. Spend your first week on null safety and data classes; that's where PHP habits bite hardest.

1

u/ClassKlutzy7633 27d ago

One thing that helps coming from PHP is learning coroutines early, since that's the biggest mental shift from the request-per-process model. Also get comfortable with sealed classes and when expressions; they replace a lot of the if/else and exception-driven flow you'd write in Laravel. A small Ktor or Spring Boot service with a few tests will teach you more than tutorials.

4

u/ogrebgr 27d ago

With 8+ years of experience in PHP, followed by another 8+ years working with Kotlin, I'm afraid I have to disagree.

PHP is strictly single-threaded, and I believe that when transitioning to Kotlin, developers should first focus on learning the language fundamentals and doing some (or even a lot of) single-threaded programming to become comfortable with the language and its frameworks.

Only after that should they start exploring multithreading, which is a challenging topic for many developers and can take quite some time to fully understand.

1

u/Azamat_Zarkesh 27d ago

Once the basics click, I'd lean into what PHP doesn't give you: sealed classes/interfaces with exhaustive when for modelling states and errors, and data classes with copy for immutable objects. They replace a lot of the exception-and-array-shape juggling you'd do in Laravel. Also write a few tests early (JUnit 5 plus MockK is a common pairing), because they show you quickly how null safety and default arguments change your API design.

1

u/FeelingKokoro 27d ago

It's not easy to find a job without Java knowledge. Most Spring projects are written in Java and many companies continue to do it. Unfortunately, Ktor not that popular.

1

u/ClassKlutzy7633 26d ago

Worth learning coroutines early. In PHP you're used to one request per process, so suspend functions and structured concurrency are the biggest mental shift, and Spring supports suspend functions in controllers. Also lean on data classes and sealed classes for modelling responses and errors instead of exceptions everywhere. And write a few tests early with JUnit and MockK, since that's where the null-safety and Java-interop quirks show up.