PHP function overloading

前端 未结 10 975
北恋
北恋 2020-11-22 17:24

Coming from C++ background ;)
How can I overload PHP functions?

One function definition if there are any arguments, and another if there are no arguments? Is it

10条回答
  •  [愿得一人]
    2020-11-22 17:37

    ";
            }
    
            else if($arg1 != null && $arg2 != null && $arg3 != null)
                {
                $volume=$arg1*$arg2*$arg3;
                echo "volume of a cuboid ".$volume ."
    "; } else if($arg1 != null && $arg2 != null) { $area=$arg1*$arg2; echo "area of square = " .$area ."
    "; } else if($arg1 != null) { $volume=$arg1*$arg1*$arg1; echo "volume of a cube = ".$volume ."
    "; } } } $obj=new abs(); echo "For no arguments.
    "; $obj->volume(); echo "For one arguments.
    "; $obj->volume(3); echo "For two arguments.
    "; $obj->volume(3,4); echo "For three arguments.
    "; $obj->volume(3,4,5); ?>

提交回复
热议问题