|
Posted by Kesavan on 03/01/07 07:53
On Mar 1, 11:47 am, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Kesavan)
>
>
>
> >I need polymorphism in php.
> >When I run this following code I get the following error.
> >Fatal error: Cannot redeclare aClass::aPrint() in C:\Program Files
> >\xampp\htdocs\k7\prCls.php on line 16
>
> >How I rectify it?
>
> ><?php
>
> > class aClass{
>
> > function aPrint($name){
> > echo $name;
> > }
>
> > function aPrint($name,$age){
> > echo $name;
> > echo $age;
> > }
> >[...]
>
> PHP doesn't support that. But you could make $age an optional argument
> and check inside the function whether it was passed or not:
>
> function aPrint($name, $age = NULL) {
> print $name;
> print !is_null($age) ? $age : '';
> }
>
> Micha
Thanks Michael,
Your trick help's me..,
Isn't PHP fully OOP language/
Kesavan M
m.kesavan@hotmail.com
[Back to original message]
|