You are here: Re: Fatal Error on Polymorphism « PHP Programming Language « IT news, forums, messages
Re: Fatal Error on Polymorphism

Posted by Michael Fesser on 03/01/07 06:47

..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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация