2020-10-08
2076
#php#wordpress
Leonardo Losoviz
26442
Oct 8, 2020 â‹… 7 min read

Transpiling PHP code from 8.0 to 7.x via Rector

Leonardo Losoviz Freelance developer and writer, with an ongoing quest to integrate innovative paradigms into existing PHP frameworks, and unify all of them into a single mental model.

Recent posts:

Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 min read
Exploring Zed, A Newly Open Source Code Editor Written In Rust

Exploring Zed, an open source code editor written in Rust

The Zed code editor sets itself apart with its lightning-fast performance and cutting-edge collaborative features.

Nefe Emadamerho-Atori
Apr 22, 2024 â‹… 7 min read
Implementing Infinite Scroll In Next Js With Server Actions

Implementing infinite scroll in Next.js with Server Actions

Infinite scrolling in Next.js no longer requires external libraries — Server Actions let us fetch initial data directly on the server.

Rahul Chhodde
Apr 19, 2024 â‹… 10 min read
View all posts

4 Replies to "Transpiling PHP code from 8.0 to 7.x via Rector"

  1. Awesome, thanks for the post! And you’re totally right, I’m a WordPress plug-in and theme developer and I’ve been wanting to use php 7 since day one. The only thing that worries me is testing. How will we know the production code works as expected? Will we have to write two sets of tests for each codebase?

  2. My idea is to run some PHP tool to analyze the downgraded code, using PHP 7.1. If the transpiling failed and PHP 7.2 was left behind, then this process will fail.

    I describe this strategy here: https://graphql-api.com/blog/graphql-api-for-wp-is-now-scoped-thanks-to-php-scoper/#heading-testing (his blog post is about scoping the code, but either scoping or downgrading, the idea is the same).

    As for what library to use, you can still use Rector, but since it requires PHP 7.3+, you must use its downgraded to PHP 7.1 version from here: https://github.com/rectorphp/rector-php71

  3. It’s me again! What’s your experience with named arguments? Have you been able to compile named arguments to positional arguments? The DowngradeNamedArgumentRector seems to only downgrade arguments from class methods. And only form the classes defined in the source code. I’m guessing it’s not possible to downgrade named arguments when using bult in functions or third party APIs like WordPress, right?

    1. So my understanding is that the classes and functions need to be loaded in memory at the time Rector is running. Any ideas on this? It seems an extremely hard thing to do considering WordPress mixes initialization logic with function definitions. Which seems like a shame, because if there’s an API we could benefit from using named arguments it’s the main WordPress Core.

Leave a Reply