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 6034111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:34:56+00:00 2026-05-23T05:34:56+00:00

A NEW UPDATE ON THE PROBLEM I wan’t the class ‘BlogPost’ to access its

  • 0

A NEW UPDATE ON THE PROBLEM

I wan’t the class ‘BlogPost’ to access its parent class variables that have been set on the main.php page

class BlogPage {
    public $PageExists = false;
    public $PageTitle = "no title";
    public $PageId = "0";
    function __construct($page){
        //some sql to check if page exists
        if($page_exists){
            $this->PageExists = true;
            $this->PageTitle = $fetched['row_title'];
            $this->PageId = $fetched['row_id'];

        }
    }
}

class BlogPost extends BlogPage {
    function __construct(){
        $page_id = $this->PageId;
        //some sql to get the posts that have post_page like $page_id
    }
}

The Main.php page

$page = new BlogPage("index");
if($page->PageExists == true){
    include("posts.php");
}else{
include("notfound.php");
}

The posts.php

$pageTitle = $page->PageTitle;
$posts = new BlogPost();

?>

  • 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-23T05:34:56+00:00Added an answer on May 23, 2026 at 5:34 am

    If you want to access parent’s class protected and public variables and functions, then you will use the parent:: static prefix.

    In your case, if you want to access classOne‘s protected and public variables and functions inside classTwo, then you will just use parent:: inside classTwo.

    If you just want to use the classTwo instantiated object on the included file, then you don’t need to declare it as global, you just access it normally as you would access it a few lines below declaring it on the main file.

    Update 1

    You don’t need to define the scope of that variable as global, because it already has that scope on that part of the script. So, just access it like this:

    // global $page; remove this, no need for it
    $pageTitle = $page->PageTitle;
    $posts = new BlogPost();
    

    Update 2

    This is my suggested solution to your second problem:

    <?php
    class Page{
        public $PageExists  = false;
        public $PageTitle   = 'no title';
        public $PageId      = '0';
        // add other options here
    
        // add other parameters to this function
        // or pass an array to it
        protected function fill($page_id, $page_title){
            $this->PageExists   =   true;
            $this->PageId       =   $page_id;
            $this->PageTitle    =   $page_title;
        }
    }
    
    class BlogPage extends Page{
        function __construct($page){
            //some sql to check if page exists
            if($page_exists){
                parent::fill($fetched['row_id'], $fetched['row_title']);
            }
        }
    }
    
    class BlogPost extends Page {
        function __construct($page_id){
            //some sql to get the posts that have post_page like $page_id
            if($post_exists){
                parent::fill($fetched['row_id'], $fetched['row_title']);
            }
        }
    }
    ?>
    

    Then you can use your classes like the following…

    On Main.php page

    <?php
    $page = new BlogPage("index");
    if($page->PageExists == true){
        include("posts.php");
    } else{
        include("notfound.php");
    }
    ?>
    

    On posts.php

    <?php
    $pageTitle  = $page->PageTitle;
    $posts      = new BlogPost($page->PageId);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have new problem with query: I want to update column 'column' depending on
I have a problem when I want to update a row in a database.
I wan't to have a function that turns spell check on then go's to
Update My problem was that I used event.preventDefault() instead of return false to hinder
UPDATE The problem is not the code, the problem is that you apparently can't
I'm new to python programming. I have this problem: I have a list of
I have a problem that I thought someone may be able to help me
12:18:55,541 INFO [UpdateChecker] New update(s) found: 2.0.0 [ http://ehcache.org/news.html] How do I suppress ehcache
EntityManager.merge() can insert new objects and update existing ones. Why would one want to
the following code (from a database object created for each new view): -(void)update:(NSString *)queryText{

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.