-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make XP compiler the Babel of PHP #299
Labels
Comments
<?php namespace test;
use util\cmd\Console;
use peer\http\HttpConnection;
// https://wiki.php.net/rfc/group_use_declarations
use peer\{ConnectException, SocketException};
// https://wiki.php.net/rfc/variadics
function println(... $_) {
// https://wiki.php.net/rfc/argument_unpacking
return Console::writeLine(...$_);
}
class Uri {
// https://docs.hhvm.com/hack/types/annotations#class-properties
// (https://wiki.php.net/rfc/property_type_hints)
private HttpConnection $conn= null;
// https://docs.hhvm.com/hack/other-features/constructor-parameter-promotion
public function __construct(private string $uri) { }
// https://github.com/xp-framework/rfc/issues/241
public function __toString(): string ==> $this->uri;
// https://docs.hhvm.com/hack/attributes/introduction
<<deprecated('Use connection() instead')>>
public function getConnection() ==> $this->connection();
// https://wiki.php.net/rfc/isset_ternary
public function connection(): HttpConnection {
return $this->conn ?? $this->conn= new HttpConnection($this);
}
}
// https://docs.hhvm.com/hack/operators/lambda
// (https://wiki.php.net/rfc/arrow_functions)
$get= (Uri $uri) ==> $uri->connection()->get();
try {
$r= $get(new Uri($argv[1] ?? 'http://localhost'));
println($r);
$s= $r->header('Content-Length')[0];
println('read(', $s, ') => ', strlen($r->readData($s)));
} catch (ConnectException | SocketException $e) {
// https://wiki.php.net/rfc/multiple-catch
println('Error ', $e->compoundMessage());
} finally {
println('Done');
} |
Developed as library |
Some interesting ECMAScript proposals matching or related to PHP RFCs and HHVM features: |
Static imports? <?php namespace demo;
use function util\cmd\Console::writeLine;
class HelloWorld {
public static function main(array $args): int {
writeLine('Hello, World!');
return 0;
}
} |
Library has reached version 0.5.0 in the meantime, looking good! |
Library has reached surpassed 1.0.0. by now and is in productive use |
thekid
changed the title
Make XP compiler the TypeScript of PHP
Make XP compiler the Babel of PHP
Oct 6, 2023
This issue was closed.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Scope of Change
This RFC suggests changing the PHP language support in the XP Compiler to support all future PHP features (at the time of writing, PHP 7). This would mean you could already start writing PHP 7 code, and could transpile it for running on older, PHP 5.5, environments.
Rationale
Ease adoption of new language features, decouple from slowly adopting production platforms and environments.
Functionality
Design principles
Compilation
Compilation can either be done explicitly by calling
xcc
or by using the JIT compiler.Features
The following are easy:
These need more investigation:
__call
...These might not work in a fast and reliable way:
Experimental support could be added for features currently under discussion:
We could also add Hack language features
array<string>
andarray<string, Object>
We might want to include support for PHP 5.6:
Security considerations
Speed impact
Dependencies
Related documents
Inspired by http://channel9.msdn.com/Events/Build/2015/3-644
The text was updated successfully, but these errors were encountered: