You are here: Re: Inheritance problem with PHP 5 objects « PHP Programming Language « IT news, forums, messages
Re: Inheritance problem with PHP 5 objects

Posted by Tony Marston on 07/22/05 12:32

Your approach is all wrong. You are defining the table name as a constant
and not putting anything in the static variable. You ought to try what I
have been doing for the past couple of years, which is to set the table name
within the constructor of the subclass, like this....

require_once 'std.table.class.inc';
class Person extends Default_Table {
function Person()
{
$this->tablename = 'person';
$this->dbname = 'sample';

} // Person
} // end class

Note that the variables $tablename and $dbname are defined in the superclass
and do not need to be redefined in each subclass.

Hope this helps.

--
Tony Marston

http://www.tonymarston.net



"bingomanatee" <edelhart@manateebay.com> wrote in message
news:1121976043.611701.227440@g43g2000cwa.googlegroups.com...
>I am having a problem with inheritance and static properties. I am
> writing a data record class object structure for Xoops.
>
> Because the table name is dynamic, I have to set it as a static member
> for each class. However I am having trouble finding a way to pass this
> static member to the subclass.
>
> for instance,
>
> /************ SAMPLE RECORD CLASS ***************/
>
> class Address_class extends Data_class {
> const TABLE_NAME = 'address';
> public static $x_table_name = '';
> public ID = 0;
>
> public function __construct($pID){
> $this->ID = $pID;
> $this->get();
> }
> }
>
> Address_class::$x_table_name = OPS_DB_PREFIX . '_' .
> Address_class::TABLE_NAME;
>
> /************** CORE DATA CLASS ***************/
>
> abstract class Data_class {
>
> function get(){
> $result = $this->execute_SQL(sprintf("SELECT * FROM %s WHERE ID =
> %d LIMIT 1;", self::$x_table_name, $this->ID));
> {--- process result --}
> }
> }
>
> /****************** END CODE ********************/
>
> The problem is that becuase it is static and in the child class, the
> value of self::$x_table_name is undefined in the context of the parent
> method get(); where because it is a normal property, I can pass ID just
> fine.
>
> Any thoughts
>

 

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

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