3v4l.org

run code in 300+ PHP versions simultaneously
<?php function build_external_url(string $host, string $path = null, array $query = [], string $schema = null, int $port = null): string { $url = $host; if (null !== $port) { $url .= ':' . $port; } if (null !== $path) { $url .= '/' . ltrim($path, '/'); } if (! empty($query)) { $url .= '?' . http_build_query($query); } return (null === $schema ? $url : ($schema . '://' . $url)); } $tests = [ [ 'foo.co' ], [ 'foo.co', '/bar' ], [ 'foo.co', 'bar', [ 'x' => 'baz' ]], [ 'foo.co', 'bar', [], 'ftp' ], [ 'foo.co', 'bar', ['email' => 'me@foo.co'], 'ftp', '24225'], ]; foreach ($tests as $args) { echo build_external_url(...$args) . PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
foo.co foo.co/bar foo.co/bar?x=baz ftp://foo.co/bar ftp://foo.co:24225/bar?email=me%40foo.co

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
95.49 ms | 405 KiB | 5 Q