Jump to content

Need help accessing an attribute from parent class


Go to solution Solved by requinix,

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;

}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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