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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:39:42+00:00 2026-06-17T21:39:42+00:00

im trying to create a class to manage widgets. I have problems with a

  • 0

im trying to create a class to manage widgets. I have problems with a protected data in parent class:

Widget.php

/** Parent class **/
class Widget{
    protected $html =""; //formated html data
    // method to load views in {system_path}/widgets/{widget_name}/views/
    protected function LoadView($filename){
        if(!empty($filename) && is_string($filename)){
            $output = "";
            $dir = WIDGET_PATH . "views" . DS . $filename;
            ob_start();
                include($dir);
                $output = ob_get_contents();
            ob_end_clean();
            return $output;
        }
        return NULL;
    }

    //method to render formated html data
    public function Render(){
        if(isset($this->html) && !empty($this->html)){
            return $this->html;
        }
        return NULL;
    }
    //static method to load a Widget
    public static function Load($widgetName){
        if(!empty($widgetName) && is_string($widgetName)){
            $widgetName = strtolower($widgetName);
            if(file_exists(WIDGET_PATH . $widgetName . DS . $widgetName . ".php")){
                include_once(WIDGET_PATH . $widgetName . DS . $widgetName . ".php");
                if(class_exists($widgetName."_Widget")){
                    $class = $widgetName."_Widget";
                    return new $class();
                }
            }
        }
        return FALSE;
    }

}

/widgets/socialbar.php

/** SocialBar Widget **/
class Socialbar_Widget extends Widget
{   
    public function __construct(){
        $this->html = "demo"; // test to see if it works
    }
}

index.php

/*load class files, etc */
$Social = Widget::Load("socialbar"); //works, perfectly loads Socialbar_Widget()

var_dump($social); // works : object(Socialbar_Widget)[29] protected html = 'demo' ......

$Social->Render(); // throws Fatal error: Using $this when not in object context

To extend a variable inside parent class should i use “public”? Or what i mistake.
Thanks for help guys.

  • 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-06-17T21:39:43+00:00Added an answer on June 17, 2026 at 9:39 pm

    Your class name is class Socialbar_Widget,
    Your are calling it in lower case

    $Social = Widget::Load("socialbar")
    

    and in load method you are doing strtolower($widgetName).
    Check class file name.php. Load function may have returning false.

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

Sidebar

Related Questions

I am trying to create a class that implements the IUnknown interface. I have
I am trying to create a single abstract class to manage input validation -
I'm trying to create a class that can manage bidimensional array. I used the
Basically I'm trying to create a SessionManager class which I can use to manage
I'm trying to create my own class to manage matrixes, but I'm a newbie
I'm trying to create a class to manage the opening of a certain file.
I'm trying to create a custom validation method in JQuery and I can't manage
I'm trying to create a class that manages the events of a combo box
I am now trying to create new database manager under Fragment class. But unfortunately,
I am trying to create class properties for each element in an array. The

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.