|
Posted by Erwin Moller on 03/01/07 10:03
Kesavan wrote:
> 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/
No, it isn't: go Java or C++ or something like that if you want 'real'
method overloading.
The support PHP gives for OOP is enough to get almost all tasks done.
Regards,
Erwin Moller
>
> Kesavan M
> m.kesavan@hotmail.com
Navigation:
[Reply to this message]
|