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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:39:51+00:00 2026-05-16T15:39:51+00:00

The only object oriented programming experience I have is from C#, so PHP is

  • 0

The only object oriented programming experience I have is from C#, so PHP is throwing me some curve balls I could use some help with.

I have a class I use for all my pages, the “pagebase” if you will. It handles the lowest level html structure. That class is inherited by several other classes. Those classes are the different page types the site has. Now: I’m having trouble setting a variable in the “pagebase” from the instance of the class that inherits it. In C# that would be no problem seeing as the class instance behaves as if it were the inherited class.

This is a representation of what I’ve got:

pagebase.php

<?php
    class pagebase
    {
        var $title = "No title";
        var $body = "<center>No content</center>";

        function setTitle($value) {
            $this->title = $value;
        }

        function setBody($value) {
            $this->title = $value;
        }

        function updateHTML()
        {
            ...
        }

        function drawPage()
        {
            $this->updateHTML();
            echo $this->html;
        }
    }
?>

std_page.php

<?php
    include("includes/pagebase.php");

    class std_page extends pagebase
    {
        function std_page()
        {
            ...
        }

        function updateHTML()
        {
            parent::setBody(
                "
                    <div id=\"main_wrapper\">
                        The page goes here!
                    </div>
                "
            );
        }

        function drawPage()
        {
            $this->updateHTML();
            parent::drawPage();
        }
    }
?>

index.php

<?php
    include "includes/std_page.php";

    $page = new std_page;
    $page->setTitle("Avesta");

    $page->drawPage();
?>

Now among other things, the biggest problem here is that NOTHING WORKS. The values in pagebase aren’t changed even though I’m getting no error indicating the function wasn’t found or run in any shape, way or form.

Someone please just inform me what I’m doing wrong – Thanks

  • 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-16T15:39:52+00:00Added an answer on May 16, 2026 at 3:39 pm

    First thing first, never declare your properties using var keyword, please define its accesibilty using public, private, or protected.

    Then when you want to access properties or method from the child class, you just need to use $this keyword. e.g $this->title, $this->setTitle('title')

    Then there is static keyword when you define property or method as static you call it using :: operator. e.g if you have public static $title then you can access that using pagebase::$title

    Hopes it clear some confusion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I read somewhere that some modules only have object oriented interfaces (
For example in classic object oriented programming I might have a class School which
I'm reading some slides of a class on object oriented programming languages and stepped
From day 1 of my programming career, I started with object-oriented programming. However, I'm
I'm new of the Object Oriented Programming methods: I have a class MyClass1 as
I was recently reading a few articles on PHP Object oriented programming and came
As a rule in object-oriented paradigm, a static method can have access only to
I am trying to understand the core of object oriented programming for php or
My first serious language was Java, so I have comprehended object-oriented programming in sense
I am fairly new to object oriented programming, so I am still having some

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.