Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 517847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:52:35+00:00 2026-05-13T07:52:35+00:00

I have created a Page class and all the pages on my website are

  • 0

I have created a Page class and all the pages on my website are objects of that Page class. Each Page object has a title attribute which is passed in as an argument to the constructor and so creating a new Page object looks as follows.

<?php

require_once('library/Page.php');

$page = new Page('About');

$page->header();

This is where the problem arises.

The header() method is…

public function header()
{   

    require_once($this->templatePath . 'header.php');

}

I then echo the page title using

<?php echo $page->title; ?>

However, I get the following error.

Notice: Undefined
variable: page in
/Users/aaronfalloon/Projects/PHP/tfm/template/header.php
on line 19

Notice: Trying to get property
of non-object in
/Users/aaronfalloon/Projects/PHP/tfm/template/header.php
on line 19

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:52:36+00:00Added an answer on May 13, 2026 at 7:52 am

    Let me further explain about what Gumbo has written.

    When you included the template file, you did the operation WITHIN the header function, thus making all $page variable in the template file referring to the local $page variable in the header function, which apparently is not declared/defined.

    You should use $this->title instead to refer to the current class.

    It is something like

    class Page{
    
      public function header(){
        echo $this->title;
      }
    
    }
    

    when you try to include the template file:

    // page class
    class Page{
    
      public function header(){
        include('template.php');
      }
    
    }
    

    .

    // template file
    echo $this->title;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a page Education For All in facebook. In my website i
I have created a web page that has two bars across the top of
I have created login page forced login in several pages. Now i need to
I have a website project. It has assembly references to external DLLs that we
I've created a form ( form website page ) that works perfectly on IE8,
I have created a sign-up and login for my website and all validation works
I am creating a website for a magazine which has a page devoted to
I have created a page on Wiki and I want to make the contents
I have created a page on my site where users can post directly to
I have created a page with a static image positioned to the ride side

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.