0
Well, I have the code below that should work but gives error:
function teste( string... $_array ) : array {
//FINS DE TESTE
return $_array;
}
print_r ( teste ( ["teste","2"] ) );
If I just do
function teste( array $_array ) : array {
//FINS DE TESTE
return $_array;
}
works!
But I’d like to specify that the array is of strings only.
How to do this in PHP?
I really wanted it to specify the type. Mainly to be able to do something like:
function() : array[array, bool] {}
, thus specifying that the function returns an array where the first is another array and the second the boolean value, which would be an error sign.– Inkeliz
Parse error: syntax error, Unexpected ':', expecting '{' in /var/www/html/gasmuriae.com.br/web/gceu/teste.php on line 7
– Carlos Rocha
line 7 is: Function test( string... $_array ) array {
– Carlos Rocha
@Carlosrocha, this works normally at http://sandbox.onlinephpfunctions.com/code/8f099274ab7cbded7c4348e8f963bff5d9521b1b (PHP 7.2).
– Inkeliz
thanks. let’s hope they improve this because ...["test","2"] is a shame for PHP 7.
– Carlos Rocha