How to use mixed parameter type in my own functions?
<p>I want to define a PHP 7 function that takes a parameter of mixed type. (What I want is the equivalent of a generic type parameter in C#; if there's a better way to emulate that in PHP 7, please let me know.)</p>

<p>My code is as follows.</p>

<pre><code>&lt;?php
declare (strict_types = 1);    

function test (mixed $s) : mixed {
    return $s;
}

// Works
echo gettype ('hello');
// Does not work
echo test ('hello');
?&gt;
</code></pre>

<p>When I run this code, I get the following.</p>

<pre><code>Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of mixed, string given, called in mixed.php on line 11 and defined in mixed.php:4
Stack trace:
#0 mixed.php(11): test('hello')
#1 {main}
thrown in mixed.php on line 4
</code></pre>

<p>If I comment out the call to test(), the code runs fine, so apparently it's at least okay for me to use the mixed parameter type in the function declaration.</p>

<p>I know built-in PHP functions such as gettype() can take mixed parameters, though I don't know if they are internally using strict typing.</p>

<p>I see that "mixed" is also used as a pseudo-type in PHP <a href="https://secure.php.net/manual/en/language.pseudo-types.php" rel="noreferrer">documentation</a>, so I might misunderstand the purpose of "mixed" as a PHP keyword, but what I'm seeing here at least implies to me that it is a legitimate keyword. Am I simply using it in a way it isn't intended for?</p>

<p>Finally, I realize I could circumvent all this by simply not specifying the parameter type, but I'd like to be consistent by specifying all my parameter and return types.</p>

<p>Thank you and please let me know if I can provide any additional information.</p>