Object delegation possible in PHP4?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin Lucas-Smith

    Object delegation possible in PHP4?



    Perhaps I'm using the wrong terminology, but is object delegation (as
    opposed to inheritance) possible?, i.e. the line

    $this->registration->displayStatu s;
    in the example below.



    E.g. if one were to call

    # Instantiate a new helpdesk
    $helpdesk = new helpdesk ('theUsername', 'thePassword');

    # Check
    $helpdesk->checkUserStatu s ();

    why does this not give the result:

    Registered

    Or do I just need some sort of other syntax?



    # Define a helpdesk application class
    class helpdesk
    {
    # Constructor
    function helpdesk ($username, $password)
    {
    # Instantiate a registration
    $this->registration = new registration ($username, $password)

    # Do more stuff in this constructor
    }

    # Some other function
    function checkUserStatus ()
    {
    $this->registration->displayStatu s;
    }
    }


    # Define a registration class which applications can use
    class registration
    {
    # Constructor
    function registration ($username, $password)
    {
    // Validation of username & password at doCheck
    $this->registered = (doCheck);
    }

    # Another function
    function displayStatus ()
    {
    echo ($this->registered ? 'Registered' : 'Not registered');
    }
    }



    Martin
  • Jan Pieter Kunst

    #2
    Re: Object delegation possible in PHP4?

    In article <Pine.SOL.4.58. 0404051858060.2 4601@yellow.csi .cam.ac.uk>,
    Martin Lucas-Smith <mvl22@cam.ac.u k> wrote:
    [color=blue]
    > $this->registration->displayStatu s;[/color]

    Without following everything line by line, so I could be wrong here, but
    could it simply be that you need to do:

    $this->registration->displayStatus( );

    i.e. () obligatory with a method call?

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    Working...