title: Fatal error: Call to a member function getObject() on a non-object
body: <p>I'm making a Social Networking Website using this book called PHP5 Social Networking. 
  I'm trying to edit the profile but I get this error</p>
  
  <p><strong>Fatal error: Call to a member function getObject() on a non-object which is referring to this following line;</strong> </p>
  
  <pre><code>if ( $registry-&gt;getObject('authenticate')-&gt;isLoggedIn() 
   &amp;&amp; ( $registry-&gt;getObject('authenticate')-&gt;getUser()-&gt;getUserID() == $this-&gt;id 
     || $registry-&gt;getObject('authenticate')-&gt;getUser()-&gt;isAdmin() == true ) )
  </code></pre>
  
  <p>I'm a newbie to PHP so any help would be appreciated greatly. </p>
  
  <p>This is the entire file; </p>
  
  <pre><code>&lt;?php
  
  /**
   * Profile model
   */
  class Profile{
  
      /**
       * The registry
       */
      private $registry;
  
      /**
       * Profile ID
       */
      private $id;
  
      /**
       * Fields which can be saved by the save() method
       */
      private $savable_profile_fields = array( 'name', 'hometown', 'university', 'gender', 'photo', 'bio', 'dob' );
  
      /**
       * Users ID
       */
      private $user_id;
  
      /**
       * Users name
       */
      private $name;
  
      /**
       * Users hometown
       */
      private $hometown;
  
      /**
       * Users University 
       */
      private $university;
  
      /**
       * Users genders
       */
      private $gender;
  
      /**
       * Users bio
       */
      private $bio;
  
      /**
       * Users dob
       */
      private $dob;
  
      /**
       * Users photograph
       */
      private $photo;
  
      private $valid;
  
      /**
       * Profile constructor
       * @param Registry $registry the registry
       * @param int $id the profile ID
       * @return void
       */
      public function __construct( Registry $registry, $id=0 )
      {
          $this-&gt;registry = $registry;
          if( $id != 0 )
          {
              $this-&gt;id = $id;
              // if an ID is passed, populate based off that
              $sql = "SELECT * FROM profile WHERE user_id=" . $this-&gt;id;
              $this-&gt;registry-&gt;getObject('db')-&gt;executeQuery( $sql );
              if( $this-&gt;registry-&gt;getObject('db')-&gt;numRows() == 1 )
              {
                  $this-&gt;valid = true;
  
                  $data = $this-&gt;registry-&gt;getObject('db')-&gt;getRows();
                  // populate our fields
                  foreach( $data as $key =&gt; $value )
                  {
                      $this-&gt;$key = $value;
                  }
              }
              else
              {
                  $this-&gt;valid = false;
              }
  
          }
          else
          {
              $this-&gt;valid = false;
          }
      }
  
      /**
       * Is the profile valid
       * @return bool
       */
      public function isValid()
      {
          return $this-&gt;valid;
      }
  
      /**
       * Sets the users name
       * @param String $name
       * @return void
       */
      public function setName( $name )
      {
          $this-&gt;name = $name;
      }
  
  
      /** 
      * Sets the users university 
      $@param String $university 
      */
      public function setUniversity( $university )
      {
          $this-&gt;university = $university;
  
      }
  
  
      /**
       * Set the users date of birth
       * @param String $dob the date of birth
       * @param boolean $formatted - indicates if the controller has formatted the dob, or if we need to do it here
       */
      public function setDOB( $dob, $formatted=true )
      {
          if( $formatted == true )
          {
              $this-&gt;dob = $dob;
          }
          else
          {
              $temp = explode('/', $dob );
              $this-&gt;dob = $temp[2].'-'.$temp[1].'-'.$temp[0];
          }
      }
  
      /**
       * Sets the hometown of users
       * @param String $hometown
       * return void
       */
      public function setHometown( $hometown )
      {
          $this-&gt;hometown = $hometown;
      }
  
      /**
       * Set the gender of the user
       * @param String $gender the gender
       * @param boolean $checked - indicates if the controller has validated the gender, or if we need to do it
       * @return void
       */
      public function setGender( $gender, $checked=true )
      {
          if( $checked == true )
          {
              $this-&gt;gender = $gender;
          }
          else
          {
              $genders = array();
              if( in_array( $gender, $genders ) )
              {
                  $this-&gt;gender = $gender;
              }
          }
      }
  
      /**
       * Sets the users bio
       * @param String bio
       * @return void
       */
      public function setBio( $bio )
      {
          $this-&gt;bio = $bio;
      }
  
      /**
       * Sets the users profile picture
       * @param String photo name
       * @return void
       */
      public function setPhoto( $photo )
      {
          $this-&gt;photo = $photo;
      }
  
      /**
       * Save the user profile
       * @return bool
       */
      public function save()
      {
          // handle the updating of a profile
          if( $registry-&gt;getObject('authenticate')-&gt;isLoggedIn() &amp;&amp; ( $registry-&gt;getObject('authenticate')-&gt;getUser()-&gt;getUserID() ==  $this-&gt;id || $registry-&gt;getObject('authenticate')-&gt;getUser()-&gt;isAdmin() == true  ) )
  
  
          {
              // we are either the user whose profile this is, or we are the administrator
              $changes = array();
              foreach( $this-&gt;saveable_profile_fields as $field )
              {
                  $changes[ $field ] = $this-&gt;$field;
              }
              $this-&gt;registry-&gt;getObject('db')-&gt;updateRecords( 'profile', $changes, 'user_id=' . $this-&gt;id );
              if( $this-&gt;registry-&gt;getObject('db')-&gt;affectedRows() == 1 )
              {
                  return true;
              }
              else
              {
                  return false;
              }
          }
          else
          {
              return false;
          }
      }
  
      /**
       * Convert the users profile data to template tags
       * @param String $prefix prefix for the template tags
       * @return void
       */
      public function toTags( $prefix='' )
      {
          foreach( $this as $field =&gt; $data )
          {
              if( ! is_object( $data ) &amp;&amp; ! is_array( $data ) )
              {
                  $this-&gt;registry-&gt;getObject('template')-&gt;getPage()-&gt;addTag( $prefix.$field, $data );
              }
          }
      }
  
  
  
      /**
       * Return the users data
       * @return array
       */
      public function toArray( $prefix='' )
      {
          $r = array();
          foreach( $this as $field =&gt; $data )
          {
              if( ! is_object( $data ) &amp;&amp; ! is_array( $data ) )
              {
                  $r[ $field ] = $data;
              }
          }
          return $r;
      }
  
      /**
       * Get the users name
       * @return String
       */
      public function getName()
      {
          return $this-&gt;name;
      }
  
  
      /**
       * Get the users photograph
       * @return String
       */
      public function getPhoto()
      {
          return $this-&gt;photo;
      }
  
      /**
       * Get the users ID
       * @return int
       */
      public function getID()
      {
          return $this-&gt;user_id;
      }
  
  }
  
  
  ?&gt;
  
  It also needs to pass through;
  profileinformationcontroller.php
  
  &lt;?php
  
  /**
   * Profile information controller
   */
  class Profileinformationcontroller {
  
      /**
       * Constructor
       * @param Registry $registry
       * @param int $user the user id
       * @return void
       */
      public function __construct( $registry, $directCall=true, $user )
      {
          $this-&gt;registry = $registry;
          $urlBits = $this-&gt;registry-&gt;getObject('url')-&gt;getURLBits();
          if( isset( $urlBits[3] ) )
          {
              switch( $urlBits[3] )
              {
                  case 'edit':
                      $this-&gt;editProfile();
                      break;
                  default:
                      $this-&gt;viewProfile( $user );
                      break;
              }   
          }
          else
          {
              $this-&gt;viewProfile( $user );
          }
  
      }
  
      /**
       * View a users profile information 
       * @param int $user the user id
       * @return void
       */
      private function viewProfile( $user )
      {
          // load the template
          $this-&gt;registry-&gt;getObject('template')-&gt;buildFromTemplates( 'header.tpl.php', 'profile/information/view.tpl.php', 'footer.tpl.php' );
          // get all the profile information, and send it to the template
          require_once( FRAMEWORK_PATH . 'models/profile.php' );
          $profile = new Profile( $this-&gt;registry, $user );
          $profile-&gt;toTags( 'p_' ); 
      }
  
  /**
   * Edit your profile
   * @return void
   */
  private function editProfile()
  {
      if( $this-&gt;registry-&gt;getObject('authenticate')-&gt;isLoggedIn() == true )
      {
          $user = $this-&gt;registry-&gt;getObject('authenticate')-&gt;getUser()-&gt;getUserID();
          if( isset( $_POST ) &amp;&amp; count( $_POST ) &gt; 0 )
          {
                      require_once( FRAMEWORK_PATH . 'models/profile.php' );
  
              // edit form submitted
              $profile = new Profile( $this-&gt;registry, $user );
              $profile-&gt;setName( $this-&gt;registry-&gt;getObject('db')-&gt;sanitizeData( $_POST['name'] ) );
              $profile-&gt;setHometown( $this-&gt;registry-&gt;getObject('db')-&gt;sanitizeData( $_POST['hometown'] ) );
              $profile-&gt;setUniversity( $this-&gt;registry-&gt;getObject('db')-&gt;sanitizeData( $_POST['university'] ) );
              $profile-&gt;setGender( $this-&gt;registry-&gt;getObject('db')-&gt;sanitizeData( $_POST['gender'] ), false );
              $profile-&gt;setBio( $this-&gt;registry-&gt;getObject('db')-&gt;sanitizeData( $_POST['bio'] ) );
              $profile-&gt;setDOB( $this-&gt;registry-&gt;getObject('db')-&gt;sanitizeData( $_POST['dob'] ), false );
              if( isset( $_POST['profile_picture'] ) )
              {
                  require_once( FRAMEWORK_PATH . 'lib/images/imagemanager.class.php' );
                  $im = new Imagemanager();
                  $im-&gt;loadFromPost( 'profile_picture', $this-&gt;registry-&gt;getSetting('uploads_path') .'profile/', time() );
                  if( $im == true )
                  {
                      $im-&gt;resizeScaleHeight( 150 );
                      $im-&gt;save( $this-&gt;registry-&gt;getSetting('uploads_path') .'profile/' . $im-&gt;getName() );
                      $profile-&gt;setPhoto( $im-&gt;getName() );
                  }
              }
              $profile-&gt;save();
              $this-&gt;registry-&gt;redirectUser( array('profile', 'view', 'edit' ), 'Profile saved', 'The changes to your profile have been saved', false );
          }
          else
          {
              // show the edit form
              $this-&gt;registry-&gt;getObject('template')-&gt;buildFromTemplates( 'header.tpl.php', 'profile/information/edit.tpl.php', 'footer.tpl.php' );
              // get the profile information to pre-populate the form fields
              require_once( FRAMEWORK_PATH . 'models/profile.php' );
              $profile = new Profile( $this-&gt;registry, $user );
              $profile-&gt;toTags( 'p_' ); 
          }
      }
      else
      {
          $this-&gt;registry-&gt;errorPage('Please login', 'You need to be logged in to edit your profile');
      }
  }
  
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>Is there anyone who can help???
  I'll send the source code to your email as well if it helps at all?</p>
  
  <p>Thanks in advance  :)</p>