Created
June 11, 2018 19:30
-
-
Save barryosull/97565a52c062c8fc67dcaac3d29a3a3d to your computer and use it in GitHub Desktop.
Typed PHP arrays via variadic function args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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