You are here: Calling a method in the parent of a parent « PHP Programming Language « IT news, forums, messages
Calling a method in the parent of a parent

Posted by Gordon on 11/09/07 09:37

I am currently rewriting a corporate CMS that was originally hacked
together in a hurry by a mamber of staff who is now leaving and which
is totally uncommented and is therefore in a state where maintaining
it would be a total nightmare. I'm redesigning it to take an OO
approach, but am limited to PHP 4 on the server on which it will run
and am therefore limited to that version's OO model.

The current plan is to have a hierarchy of classes going from the
general to the specific and inherit and override/extend functions as
necessary to achieve the desired results. At the top of the chain is
a CMS item object that defines props and methods that are common to
all items that will be stored by the CMS: Creation/last modified
dates, summaries, filesystem paths etc. From that I dreive classes
for specific types of CMS data. Documents, images and directories all
decend directly from the CMS item class.

As I was designing I originally intended for there to be a site class
that inherited from the item class, but as the design progressed I
realised that a site is basically a special case of a directory and
therefore should be derived from the directory class.

But here I hit a snag, because I need to access a method in the item
class while bypassing the same method in the directory class. In the
item class is a method that inserts some data into the items table of
the database. In the directory class this method is extended by
another method of the same name. This method runs the method in the
parent class with parent::method(), then does the extra SQL queries
that it needs to do for creating a directory.

The site class, however, uses a different pair of tables (item and
site) to the directory class (item and directory). This means that
the method in the site class needs to call the parent's parent method
directly without calling the parent's method. I tried both
parent::parent::method() and parent::parent -> method() but both of
these threw an error

Is there a way to call a method that's further than 1 class up the
inheritance chain?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация