SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Thread: polymorphism?

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    polymorphism?

    i want 2 different objects created using the same definition based on parameters.. ie:

    PHP Code:
    $myobject = new Animal'dog' );
    $myotherobject = new Animal'cat' );

    // i now have to instances of same object

    echo $myobject->getNoise(); // will output "mew"
    echo $myotherobject->getNoise(); // will output "bark" 
    right now, i just have a switch statement in the getNoise method based on the parameter in the constructor, but is it possible to keep 2 seperate object definitions using the same declaration?

    php v 4.3.9
    Last edited by Gasolene; Apr 28, 2005 at 14:23.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •