1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

overloading PHP

Discussion in 'PHP' started by iago111, Aug 31, 2020.

  1. #1
    Hello,
    I had a question concerning overloading in PHP, which is not possible.
    Is there an elegant way to do this? I read s.th. about using the factory pattern with a private constructor.

    The background is this, I have a User class and I want to differentiate between the current user, with no constructor-parameter (I fetch the id from the session) and with an other user, with one parameter: __construct($id)?

    Thanks, iago
     
    Solved! View solution.
    iago111, Aug 31, 2020 IP
  2. #2
    try

    __construct($id=null)

    then if id is null you have to search the session.
     
    sarahk, Aug 31, 2020 IP
    Efetobor Agbontaen likes this.
  3. iago111

    iago111 Member

    Messages:
    99
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #3
    Ok, that makes sense, thanks!
     
    iago111, Sep 1, 2020 IP
    sarahk likes this.