Jump to content

Need help accessing an attribute from parent class


eldan88

Recommended Posts

Hey,

 

 I currently have a class named Photograph. In this class I have a attribute called $db_fields  that contains an array of a list of values which are in my database .

 

I also  have a parent class called database_object.php. In database_object class I have a protected method named attributes().

 

The point of the attributed is to run a foreach() on the $db_fields attribute that is located on the photograph.php class. Every-time  it tries  to run a foreach i keep getting this warning.

 Access to undeclared static property: database_object::$db_fields.

 

I need the the self::$db_fields to be the Photograph::$db_fields not $database_object::$db_fileds. Is this an example of "Late static bindings"? If so how can I correct this?

 

Thanks

 

Database  Object parent class

class database_object {

protected function attributes() {
	$attributes = array();

	foreach(self::$db_fields as $field) {
		if(property_exists($this, $field)) {
			$attributes[$field] = $this->$field;
		}
	}
	return $attributes;
}

}


Photograph Class

class Photograph extends database_object  {
	protected static $table_name = "photographs";
	protected  $db_fields=array('id','filename','type','size','caption'); // This is the array I need the attribute function to go through
	public $id;
	public $filename;

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.