PeachPie 1.0.5

Introducing the next release of PeachPie – the PHP compiler for .NET. This minor update brings new internal features and improvements, and improvements of existing features.

8bit strings

Applications built on PeachPie have native support for both UTF16 strings and 8bit string values. It represents some kind of transition between the old C-style world and the new .NET world. However, this also introduces a set of issues and challenges. You can read more at PeachPie Documentation – Unicode.

In this release, the 8bit values (strings consisting of byte sequences) are respected and persisted, and well-understood by the mb_ functions. Moreover, string literals using the \x sequences are compiled as byte sequences instead of System.String literals. In addition, the string PHP type hint also respects the 8bit string values and does not corrupt the byte sequence (which it did in previous releases).

<?php
echo "\x88áéó";
// <-- this effectively sends byte x88,
// and then Unicode characters áéó to the output stream,
// using the response encoding.

This solves the problem with 8bit values being corrupted by encoding them to UTF16 in most of the operations. The operations like echo, and almost all the library functions accepting a parameter as string work natively with Unicode strings, 8bit values are seamlessly decoded.

Nullable

System.Nullable{T} is a .NET value type representing either the value itself or null. This is actually much more useful for PHP applications . All the values are usually NULL before they get assigned something. Also, recent versions of PHP introduce nullable type hint as well. How convenient.

The compiler and runtime are now internally able to use the Nullable{T} value type. You can read more at PeachPie Documentation – CLR vs. PHP types. This helps in the upcoming releases where PeachPie will generate better strongly typed method signatures taking advantage of System.Nullable{T}.

Base Class Library

The base class library (BCL) itself got updated as well. BCL is represented by all the Peachpie.Library.* packages, containing all the built-in PHP functions, classes, interfaces, and constants.

The update includes DateTime improvements, date parsing improvements, added "date.timezone" INI option, and more. We also reduced memory allocations and implemented other optimizations.

Fixes

The update was tested by many users on various different PHP applications. Thanks to them we’ve been able to fix a bunch of bugs, such as incorrect comparison operators in case of 8bit string values, corrected conversions between numbers (between double, long, and string), and more.

Get Started

For existing PeachPie projects, just raise the number from 1.0.0 to 1.0.5 in your project .msbuildproj file:

<Project Sdk="Peachpie.NET.Sdk/1.0.5">
  <PropertyGroup>
    <OutputType>library</OutputType>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**/*.php" />
  </ItemGroup>
</Project>

For new projects, take a look at our Get Started, and let us know on our Gitter – PeachPie.

Conclusion

This update extends PeachPie’s compatibility with PHP, allowing us to run even more stuff on .NET. We are getting things ready for the next major release of WordPress 5.7.1 on .NET and we’ll be working on running PHP in WebAssembly right in your browser and other interesting usecases. Look out for an exciting announcement on WpDotNet in the next couple of weeks.

Posted on April 28, 2021, in category Uncategorized, tags: , , , , , , ,