Quantcast
Channel: User Jack - Stack Overflow
Viewing all articles
Browse latest Browse all 40

Can I pass a type as parameter in PHP?

$
0
0

I'd like to pass (any type, not only PHP's primitives) Type as a function parameter. More like a C++'s template. Is it possible in PHP? imaginary code:

function foo(T a){   $output = new T();   //do something.}

I tried pass the type name as string and then use settype() to the the variable to that type but settype() work only with PHP's primitives types. My goal is actually pass a class type as parameter.


Viewing all articles
Browse latest Browse all 40

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>