Hi, I’m trying to write code to achieve php polymorphism. I don’t know where there is a mistake in the code. It shows the error in “Fatal error: Cannot redeclare Sample::a() “. Here is my code. Kindly solve this problem.
<?php
class Sample
{
public function a()
{
echo "hi";
}
public function a($chr)
{
for ($chr=0;$chr<10;$chr++)
echo $chr;
}
public function a($b,$c)
{
for($g=$b;$g<$c;$g++)
echo $g
}
}
$s=new Sample();
$s->a();
$s->a($chr);
$s->a(1,10);
?>
http://www.php.net/manual/en/language.oop5.overloading.php
See the above link. I think it will help you.