Jump to content

elme

New Members
  • Posts

    2
  • Joined

  • Last visited

elme's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you everyone, eventually i upgraded my php to 5.4 and used "trait"
  2. I've got some classes, and each of those classes have a collection of static functions which returns an instance of those classes, instead of having those functions in 20 different classes, I tried to move them to a parent class and inherit that class. The problem is, when I use "return new self" from the parent class, it won't return the properties of the child it's been called from. Here's a simple example of what i am trying to do - <?php class Personal_Details{ static function create_user(){ return new self; } } class Female_User extends Personal_Details{ public $gender = "f"; } class Male_User extends Personal_Details{ public $gender = "m"; } $new_user = Male_User::create_user(); echo $new_user->gender; ?> I guess I'm using the wrong logic here, but how can i make this work the way i intended to? Thans.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.