Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 95845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:43:19+00:00 2026-05-10T23:43:19+00:00

I have a database structure that has a Person table which contains fields such

  • 0

I have a database structure that has a Person table which contains fields such as name, email, company_id, personType and the like. Because not all Person’s are necessarily system user’s, I have a separate table User that defines userName and password for those Person’s that are User’s in the system.

I have the following code to define the Table Data Gateway for the Person Table:

class Model_Table_Person extends Zend_Db_Table_Abstract {     protected $_name = 'person';     protected $_primary = 'person_id';      protected $_referenceMap = array(         'Company' =>    array(             'columns' => 'company_id',             'refTableClass' => 'Company',             'refColumns' => 'id'         ),         'Store' =>  array(             'columns' => 'store_id',             'refTableClass' => 'Store',             'refColumns' => 'id'         )     );      public function findByPersonType(string $personType)     {         $where = $this->getAdapter()->quoteInto('personType = ?', $personType);         return $this->fetchAll($where);     } } 

And this code defines the domain object for Person:

class Model_Person {     protected static $_gateway;      protected $_person;      public static function init()     {         if(self::$_gateway == null)         {             self::$_gateway = new Model_Table_Person();         }     }      public static function get(string $searchString, string $searchType = 'id')      {         self::init();          switch($searchString)         {             case 'id':                 $row = self::$_gateway->find($id)->current();                 break;         }          return self::factory($row);     }      public static function getCollection(string $searchString, string $searchType = null)     {         self::init();          switch($searchType)         {             case 'userType':                 $row = self::$_gateway->findByPersonType($searchString);                 break;             default:                 $personRowset = self::$_gateway->fetchAll();                 break;         }          $personArray = array ();          foreach ($personRowset as $person)         {             $personArray[] = self::factory($person);         }          return $personArray;     }      public function getCompany()     {         return $this->_person->findParentRow('Company');     }      public function getStore()     {         return $this->_person->findParentRow('Store');     }      protected static function factory(Zend_Db_Table_Row $row)      {         $class = 'Model_Person_' . ucfirst($row->personType);         return new $class($row);     }      // protected constructor can only be called from this class, e.g. factory()     protected function __construct(Zend_Db_Table_Row $personRow)     {         $this->_person = $personRow;     } } 

Lastly, I have another Table Data Gateway for User:

class Model_Table_User extends Zend_Db_Table_Abstract {     protected $_name = 'user';     protected $_primary = 'person_id';      public function findByUserName()     {      } } 

And a basic class that extends the Model_Person table like this:

class Model_User extends Model_Person {            public function login()     {      }      public function setPassword()     {      }    } 

How do I properly extend the ‘Model_User’ class (which serves a basic type for all other types of users but one) to use the ‘Model_Person’ class functions which map to one table while also mapping the actual ‘Model_User’ functions to use a second table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:43:20+00:00Added an answer on May 10, 2026 at 11:43 pm

    This is a huge weakness for PHP (prior to version 5.3.0) — its lack of support for late static binding.

    That is, when one static method such as get() calls another static method such as init(), it always uses the init() method defined in that class. If a subclass defines an alternative method init() and calls get(), expecting it to call the overridden version of init(), this won’t happen.

    class A {   static $var = null;   static function init() { self::$var = 1234; }   static function get() { self::init(); } }  class B extends A {   static function init() { self::$var = 5678; } }  B::get(); print B::$var . '\n';  

    This prints ‘1234’ whereas you might expect it to print ‘5678’. It’s as if A::get() doesn’t know that it’s part of class B. The workaround has been that you have to copy the implementation for the get() method into the subclass, even if it does nothing differently from the superclass. This is very unsatisfying.

    PHP 5.3.0 attempts to fix this, but you have to code it slightly differently in get():

    function get() {   static::init(); } 

    PHP 5.3.0 is still in alpha release currently.


    There are a few possible workarounds:

    • Don’t subclass Person as User, but instead add the login and password attributes to the Person class. If those attributes are NULL, then it’s a non-user person, and the functions login() and setPassword() should heed this and throw an exception or return false or something.

    • Use a different get() method per subtype: getUser(), getPerson(), etc. Each of these would initialize its own respective Table object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Final Update: Bug caused by standalone ie6 run on vista.… May 11, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer SELECT posts.* FROM listen JOIN posts ON posts.userid = listen.listenid… May 11, 2026 at 9:03 pm
  • Editorial Team
    Editorial Team added an answer I think a good way to define an interface is… May 11, 2026 at 9:03 pm

Related Questions

This is a simplification of the issue (there are lots of ways of doing
I’m on the learning curve up the Silverlight trail. I’m a data-centric developer so
I have an idea for how to solve this problem, but I wanted to
I am providing a web service to be called by external companies. The required

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.