Skip to content

Instantly share code, notes, and snippets.

@barryosull
Created June 11, 2018 19:30
Show Gist options
  • Save barryosull/97565a52c062c8fc67dcaac3d29a3a3d to your computer and use it in GitHub Desktop.
Save barryosull/97565a52c062c8fc67dcaac3d29a3a3d to your computer and use it in GitHub Desktop.
Typed PHP arrays via variadic function args
<?php
class TestObject
{
}
function onlyAcceptArrayOfTestObjects(TestObject ...$objects)
{
echo "Got ".count($objects)." TestObjects\n";
}
$objects = [
new TestObject(),
new TestObject(),
new TestObject()
];
onlyAcceptArrayOfTestObjects(...$objects);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment