Anything like C++ templates but for PHP out there???
I have a LOT of code in my project that could be eliminated through code reuse using something like C++ templates. Is there such a thing for PHP out there?
(Note that I am not talking about presentation templates like Smarty)
Maybe a plugin into Zend Studio that would generate code using these templates???
Thanks!
Marvin
C++ Templates but for PHP?
Moderator: General Moderators
Re: C++ Templates but for PHP?
Well, that depends on the issue at hand (could you elaborate, btw?). When I was programming in C++ - and that was a looong time ago, so my memory could be a little dim - the main use case for templates was implementing generics in a type-safe fashion. Since PHP is dynamically typed language it's not an issue here - you don't need SplMaxHeap<Transaction> because there's no compile-time type checks and you could simply use SplMaxHeap with whatever type you need.mherbold wrote: I have a LOT of code in my project that could be eliminated through code reuse using something like C++ templates. Is there such a thing for PHP out there?
Of course, there are some common use cases for code generation in PHP - generating local stubs from wsdl definitions, or generating active record classes from database structure, or CRUD scaffolding based on aforementioned active record class structures - however none of them require extending the base language in a way templates are extending C++.