Hi, how to overload construct in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abraralam08
    New Member
    • Jul 2008
    • 1

    Hi, how to overload construct in php

    Hi
    I m trying 2 overload constructor but find fatal error .
    Is constructor overloading is not allowed in php ?
    can anybody help me, I m new in php.
    thx
  • realin
    Contributor
    • Feb 2007
    • 254

    #2
    in PHP5 you can define constructor using

    [PHP]function __construct()[/PHP]

    this goes with the base as well as sub classes. You should keep in mind, that parent constructors are not automatically called when making an instance of a child class(unlike java).

    You can find this thread relevant to parent/child constructor discussion, Here

    It would be good/easy if you paste you code in here ..

    Cheers !!
    Realin !

    Comment

    • code green
      Recognized Expert Top Contributor
      • Mar 2007
      • 1726

      #3
      Function overloading in the true OOP sense is not supported in PHP.
      There is the _get _set _call method overloading.
      These methods will only be triggered when your object or inherited object doesn't contain the member or method you're trying to access
      Why would anyone want to do that?
      Anyway, if you want to cheat overloading a constructor C++ style
      you could call secondary functions within the constructor depending on a condition.
      Remember a constructor cannot return a user variable.

      Comment

      Working...