hi all.

isn't it possible to overload the constructor of a class?

function className()
{
echo "this is an empty constructor";
}

function className($asdf)
{
echo "the var $asdf has been declared!";
}

is this not possible on some php versions? because on my localhost it works fine, but on my hoster it says

"can not redeclare className"!

thanks for replies!

j0sh

    From php5 onwards Overloading was introduced, so if your host has < php 5 it will not work.

      Not directly in any version I'm aware of - how do you manage it with your local copy?

      class foo{
      function foo(){}
      function foo($bla){}
      }

      Fatal error.

      Look at [man]func_get_args[/man] and related functions, and also into giving function arguments default values.

        thats strange, because i'm using php4.x (phpDev423 from www.firepages.com.au) on localhost which definitely not is php5. :eek:

          Neither PHP4 nor PHP5 support method overloading. Period.

          What's happening is that Josh has different error reporting modes between his local host and his other site. His local host is not outputting the notices.

          Add
          error_reporting(E_ALL);
          to the top of the file and watch what happens on your local host.

            Hmm i was under the impression it did i heard it from someone PHP 5 will have overloading it even has its own page :bemused: but its blank :glare:

              Originally posted by planetsim
              Hmm i was under the impression it did i heard it from someone PHP 5 will have overloading it even has its own page :bemused: but its blank :glare:

              Thanks to the func_get_args, overloading isn't neccessary. I think at one point it was being considered, but I know it didn't make it into the final build.

                that sounds comprehensable to me now. thanks.

                btw how is func_get_args() an option for overloading?

                  function foo()
                  {
                  $args = func_get_args();
                  ...
                  }

                  Do whatever you like on the basis of what is contained in $args.

                    Write a Reply...