tags:

views:

1548

answers:

4

So I'm refactoring my code to implement more OOP. I set up a class to hold page attributes.

class PageAtrributes 
{
 private $db_connection;
 private $page_title;

 public function __construct($db_connection) 
 {
  $this->db_connection = $db_connection;
  $this->page_title = '';
 }

 public function get_page_title()
 {
  return $this->page_title;
 }

 public function set_page_title($page_title)
 {
  $this->page_title = $page_title;
 }
}

Later on I call the set_page_title() function like so

function page_properties($objPortal) {    
    $objPage->set_page_title($myrow['title']);
}

When I do I receive the error message "Call to a member function set_page_title() on a non-object."

So what am I missing?

A: 

That objPage does not refer to an instance of the PageAtrributes object (or indeed, any object). Try a var_dump on the previous line to see what it actually is.

Adam Wright
+2  A: 

It means that $objPage is not an instance of an object. Can we see the code you used to initialize the variable?

Allain Lalonde
A: 

Let's see the code where you're instantiating to $objPage. Sounds like you have a null variable ($objPage).

Brian Warshaw
A: 

I realized that I wasn't passing $objPage into page_properties(). It works fine now.

Scott Gottreu