3v4l.org

run code in 300+ PHP versions simultaneously
<?php function applyDocumentCasts($keyPattern, Closure $closure) { $casts = [ 'unchanged' => fn ($item) => $item, 'object' => fn ($item) => (object) $item, // 'Serializable' => fn ($item) => new BSONDocument($item), // 'Document' => fn ($item) => Document::fromPHP($item), ]; return array_combine( array_map(fn ($castName) => sprintf($keyPattern, $castName), array_keys($casts)), array_map(fn ($cast) => $closure($cast), $casts), ); } function provideFilterDocuments(): array { $expectedQuery = (object) ['x' => 1]; return applyDocumentCasts( '%s', fn ($cast) => [$cast(['x' => 1]), $expectedQuery] ); } var_dump(provideFilterDocuments());
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { ["unchanged"]=> array(2) { [0]=> array(1) { ["x"]=> int(1) } [1]=> object(stdClass)#1 (1) { ["x"]=> int(1) } } ["object"]=> array(2) { [0]=> object(stdClass)#6 (1) { ["x"]=> int(1) } [1]=> object(stdClass)#1 (1) { ["x"]=> int(1) } } }

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:
26.62 ms | 406 KiB | 5 Q