Re: Why no overloading in PHP5?
[color=blue]
>"Terje Slettebø" <tslettebo@hotm ail.com> wrote in message
>news:110673440 6.359050.69950@ z14g2000cwz.goo glegroups.com.. .
>Yes, that's one way, but then the class has to implement the
>PrintInterface . If it doesn't, e.g. a third party class not
>implementing that interface, then you can't use the above function.
>Then you would need to modify it for each type. With only three cases,
>as above, the code is reasonably clear. However, with many types,
>unless you make some kind of uniform dispatch mechanism to other
>functions, it can quickly grow into a rather large and messy
>switch-case or if-else ladder.[/color]
In the case of printing object, how else could you have implemented it? I
mean if it's a third party class, you have no access to its properties and
no idea how the data should be formatted.
There aren't that many scalar types in PHP. About the only ones where the
default type-conversion might be inadequate are boolean, null, and float. So
six if clauses--hardly something to sweat about.
[color=blue]
>"Terje Slettebø" <tslettebo@hotm ail.com> wrote in message
>news:110673440 6.359050.69950@ z14g2000cwz.goo glegroups.com.. .
>Yes, that's one way, but then the class has to implement the
>PrintInterface . If it doesn't, e.g. a third party class not
>implementing that interface, then you can't use the above function.
>Then you would need to modify it for each type. With only three cases,
>as above, the code is reasonably clear. However, with many types,
>unless you make some kind of uniform dispatch mechanism to other
>functions, it can quickly grow into a rather large and messy
>switch-case or if-else ladder.[/color]
In the case of printing object, how else could you have implemented it? I
mean if it's a third party class, you have no access to its properties and
no idea how the data should be formatted.
There aren't that many scalar types in PHP. About the only ones where the
default type-conversion might be inadequate are boolean, null, and float. So
six if clauses--hardly something to sweat about.
Comment