With over 400 changes, it was time for the next major release of the PeachPie platform. During the past months, we have focused on improving the compatibility with several standard PHP applications and frameworks, and on the integration with toolings such as Visual Studio.
0.9.920 is a preview release that provides you with the latest features and improvements. Basically we have focused on three major areas:
- User experience (debugging and diagnostics).
- General bug fixes (supporting more frameworks and libraries).
- More standard library (docs.peachpie.io/compatibility-status).
Debugging of eval’ed code
Eval() allows for the compilation and execution of code created at runtime. .NET+Roslyn+PeachPie all combined allow for a neat feature that is not available to PHP developers (AFAIK).
Internally, eval() compiles the given code, loads the assembly in-memory, locates the entry point method and invokes it. Now, in case a debugger is attached to your PHP application, it also generates an embedded document into the in-memory PDB (the document consists of the dynamic source code of the eval’ed code) and emits the corresponding sequence points. Check out the animation below; the right tab with the dynamic code content opens once the developer steps into it. It is loaded from the in-memory portable PDB’s embedded document.
As a result, the .NET debugger allows you to step in, step through and put breakpoints inside. This is incredibly useful for allowing developers to inspect variables and objects in the dynamic code. Also in case an exception inside the dynamic code happens, the developer now sees the exact location, including the code itself.
How does this help us? PHP’s test frameworks, mocks, database abstractions and templating engines, such as Twig, are full of eval’s. This allows us to debug into it conveniently. Read more at peachpie.io/2020/03/debugging-eval-visual-studio.html.
Debugging into Phar archives
Phar is an archive of PHP scripts, something like a zip or NuGet file. The content of the file is usually encoded, compressed, and unreadable for human eyes. Similarly to eval(), PeachPie generates embedded documents and sequence points; however, it is all done already at compile time.
PeachPie decodes the Phar file at compile-time, and newly it emits sequence points and corresponding embedded documents right into the assembly’s corresponding PDB file. It allows developers to compile and conveniently debug code inside those archives out of the box.
Precise debug sequence points
When debugging, C# developers are used to certain rules, flaws, breakpoint locations, debugging steps and behavior in general. The standard PHP (Zend) engine behaves differently; for example, expressions only report their line number, there is no column information, and you don’t have breakpoints on brackets and other empty language constructs.
PeachPie now emits very precise and C#-like sequence points enabling stepping through the code statement-by-statement, allowing you to put breakpoints on opening braces, inside lambda functions, or on multi-lined expressions. Or, as depicted above, it allows to step through the
foreach statement as it internally moves next (
as keyword) and reads
key from the iterator.
Detailed compile-time diagnostics
There is a reason why compilers are often rather referred to as code analyzers. Since the compiler has to emit valid IL instructions, it first performs detailed code analysis. See docs.peachpie.io/php/diagnostics for the list of the most common warnings and errors PeachPie reports. Since this release, there are a few more diagnostics handling more real-world applications and more detailed messages.
For example, it now checks for a very trivial issue where an override method has a different letter casing than the overriden one (see the warning
PHP6005 above). It is a very innocent typo in PHP, but .NET metadata is case sensitive, so both the compiler and the runtime have to deal with it, causing an unnecessary overhead.
The community has been doing a phenomenal job discovering issues, creating projects on GitHub, preparing automatic tests and giving us feedback.
- WooCommerce: there is an ongoing project to run WordPress & WooCommerce on .NET Core. Thanks to the work of the community, all the reported issues have been fixed, so the project now compiles and runs out of the box. It still needs some testing and thinking about the options of how to support the vast array of WooCommerce plugins conveniently.
- Laravel, Symfony and Slim Framework 3: all in progress and looking really close to working. Stay up to date on our progress with these.
- WordPress: we’ve been using WordPress as our reference project for quite a while already to demonstrate how even a massive PHP code base can run on .NET, including some options on how to integrate C# and PHP in both ways.
- domPDF: a great PHP library that creates a PDF out of HTML. This now runs nicely on .NET, allowing C# devs to make use of it seamlessly in their apps.
- Twig: a templating engine you can find in pretty much all major projects, e.g. Drupal or Symfony. It is easy to maintain and well documented. In case devs want to share their templates between PHP and ASP.NET pages, feel free to grab the library at nuget.org/packages/Twig.AspNetCore/.
- MediaWiki: in progress.
General bug fixes and more standard functions
- Improved PDO, Sqlite and other database operations.
- General compatibility and stability issues addressed.
- OpenSSL, GetText, Password extensions.
- Curl, Date, Json, SPL, mbstring, standard, extensions updated.
- DOM extension improvements.
- PCRE extension fixes.
- Fixed issues with generators, traits, and anonymous functions.
- Compiler override resolution fixes.
- Compiler exception fixes.
- More compile-time diagnostics.
$argcin console application fixes.
As you can see, this has been one of the largest releases of the PeachPie platform in a long time. We highly recommend updating or using this new release to test apps that previously couldn’t be executed on PeachPie.