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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:45:44+00:00 2026-06-05T20:45:44+00:00

I’m implementing a PHP (5.4.4) class for including class definitions (in a dynamic fashion)

  • 0

I’m implementing a PHP (5.4.4) class for including class definitions (in a dynamic fashion) for HTML rendering, so if I have a form with two buttons, four text inputs and a checkbox, I just include the .php files corresponding to a form, a textbox and a button, and not anything else (each HTML object is represented with a class).

But I have a problem… I created a class called ComponentManager for managing the loading process, with this code:

    class ComponentManager {
    // component manager properties
    protected $components;

    // constructor for this object
    public function __construct() {
        if (!empty($_SESSION['components'])) {
            $this->components = explode(" ", $_SESSION['components']);
        } else {
            $this->components = null;
        }
    }

    // destructor for this object
    public function __destruct() {
        $this->components = null;
    }

    // getter for this object
    public function __get($property) {
        if ($property === "components") {
            return $this->components;
        }
    }

    // addComponents - add components to the current components list
    public function addComponents($components) {
        if (!empty($components)) {
            $list = explode(" ", $components);

            $count = sizeof($list);
            for ($i = 0; $i < $count; $i++) {
                if (!in_array($list[$i], $this->components)) {
                    $this->components[] = $list[$i];
                    $component = null;

The problem is I seem to be failing with the in_array() function and I don’t know why… I mean, I’ve used it a lot of times in the past for different things but keeps telling me this:

Warning: in_array() expects parameter 2 to be array, null given in D:\apache\htdocs\webapps\skeleton\assets\scripts\manager.php on line 34

I pass $components in my test code as a whitespace-separated list, like this:

$page->addComponents("form checkbox textbox button range number");

My intention is to specify: if the component list is not empty, give me an array with the entered components, and for each one of the components, insert it if and only if it’s not already present in the components array.

What am I doing wrong?

  • 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-05T20:45:45+00:00Added an answer on June 5, 2026 at 8:45 pm

    Obviously, your constructor initiates $this->components to null and then you are trying to access that through addComponents().

    You probably meant to initiate it to $this->components = array(); so the list starts as an empty array, thus allowing you to use in_array() on it?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.