Re: __call() and interfaces

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I find __call() to be a nasty solution, particularily from a
self-documenting code point of view.  I personally only use call when
the function names are defined at run time; as you clearly know the
function names, I would be implementing them as normal functions.

If there is a lot of repeated code, implement the repeated code in a
private function.  Each of your methods then does it's own unique thing,
calling the private function for the common processing.  This way you
don't have any copy-paste code, you implement your Interface and your
code is easy to read, understand and maintain.


David

Mike Pfaff wrote:
> Hello World :)
> 
> I need to write a class that implements a predefined interface. In my
> class all(or most) methods will use the same code. At first i thought
> the ideal solution would be to handle this by defining the magic
> __call() method in my class, but PHP then complains about the interface
> not being completely implemented. (Is there no way to tell PHP that the
> methods are handled by __call()?)
> 
> Options i see right now:
> a) Just omit "implements SomeInterface" and PHP will stop complaining.
> This would be suboptimal as i want my class to "officially" conform to
> the standardized API which is defined in the interface.
> b) Implement all methods and just copy-paste the code. I find this
> rather ugly and it's a hassle to maintain. Is there a better solution
> than copy-paste(Keep in mind that the methods vary in argument types,
> argument counts and return value types)?
> 
> Somehow neither a) nor b) seems "the right way" to do what i want, so i
> would be glad to hear your opinions on this. I would also be interested
> what the best solution would be from a performance point of view.
> 
> Regards,
> Mike
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux